Skip to content

Commit e462199

Browse files
committed
Added frontmatter export
1 parent 9e49cf7 commit e462199

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

Source/AlephNote.App/AlephNote.App.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<AssemblyProduct>AlephNote.App</AssemblyProduct>
1717
<AssemblyCopyright>Copyright © 2021</AssemblyCopyright>
1818

19-
<AssemblyVersion>1.7.15.0</AssemblyVersion>
20-
<AssemblyFileVersion>1.7.15.0</AssemblyFileVersion>
21-
<AssemblyInformationalVersion>1.7.15.0-master</AssemblyInformationalVersion>
19+
<AssemblyVersion>1.7.16.0</AssemblyVersion>
20+
<AssemblyFileVersion>1.7.16.0</AssemblyFileVersion>
21+
<AssemblyInformationalVersion>1.7.16.0-master</AssemblyInformationalVersion>
2222

2323
<OutDir>..\..\Bin\$(Configuration)\</OutDir>
2424
</PropertyGroup>
@@ -97,4 +97,8 @@
9797
<PackageReference Include="WPFToolkit" Version="3.5.50211.1" />
9898
</ItemGroup>
9999

100+
<ItemGroup>
101+
<Reference Include="System.Web" />
102+
</ItemGroup>
103+
100104
</Project>

Source/AlephNote.App/Resources/themes/default.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Repository: https://github.com/Mikescher/AlephNote
1313
<theme>
1414
<meta>
1515
<name>Default</name>
16-
<version>1.7.15</version>
17-
<compatibility>1.7.15</compatibility>
16+
<version>1.7.16</version>
17+
<compatibility>1.7.16</compatibility>
1818
<author>Mike Schwörer</author>
1919
<type>default</type>
2020
</meta>

Source/AlephNote.App/WPF/Windows/MainWindow.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@
6565
<ctrl:AutoActionMenuItem Header="Duplicate Note" AlephAction="DuplicateNote" Settings="{Binding Settings}" />
6666
<ctrl:AutoActionMenuItem Header="Pin / Unpin Note" AlephAction="PinUnpinNote" Settings="{Binding Settings}" />
6767
<ctrl:AutoActionMenuItem Header="Lock / Unlock Note" AlephAction="LockUnlockNote" Settings="{Binding Settings}" />
68-
<ctrl:AutoActionMenuItem Header="Export Note" AlephAction="ExportNote" Settings="{Binding Settings}" />
69-
<ctrl:AutoActionMenuItem Header="Delete Note" AlephAction="DeleteNote" Settings="{Binding Settings}" />
70-
<Separator />
71-
<ctrl:AutoActionMenuItem Header="Exit" AlephAction="AppExit" Settings="{Binding Settings}" />
68+
<ctrl:AutoActionMenuItem Header="Export Note" AlephAction="ExportNote" Settings="{Binding Settings}" />
69+
<ctrl:AutoActionMenuItem Header="Delete Note" AlephAction="DeleteNote" Settings="{Binding Settings}" />
70+
<Separator />
71+
<ctrl:AutoActionMenuItem Header="Export all as Markdown + Front Matter" AlephAction="ExportFrontmatter" Settings="{Binding Settings}" />
72+
<Separator />
73+
<ctrl:AutoActionMenuItem Header="Exit" AlephAction="AppExit" Settings="{Binding Settings}" />
7274
</MenuItem>
7375
<MenuItem Header="_Edit">
7476
<ctrl:AutoActionMenuItem Header="Settings" AlephAction="ShowSettings" Settings="{Binding Settings}" />

Source/AlephNote.App/WPF/Windows/MainWindowViewmodel.Commands.Note.cs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using MSHC.Lang.Collections;
1313
using Ookii.Dialogs.Wpf;
1414
using ScintillaNET;
15+
using System.Web;
1516

1617
namespace AlephNote.WPF.Windows
1718
{
@@ -30,7 +31,8 @@ public partial class MainWindowViewmodel
3031
public ICommand DuplicateNoteCommand => new RelayCommand(DuplicateNote);
3132
public ICommand PinUnpinNoteCommand => new RelayCommand(PinUnpinNote);
3233
public ICommand LockUnlockNoteCommand => new RelayCommand(LockUnlockNote);
33-
public ICommand InsertHyperlinkCommand => new RelayCommand(InsertHyperlink);
34+
public ICommand ExportFrontmatterCommand => new RelayCommand(ExportFrontmatter);
35+
public ICommand InsertHyperlinkCommand => new RelayCommand(InsertHyperlink);
3436
public ICommand InsertFilelinkCommand => new RelayCommand(InsertFilelink);
3537
public ICommand InsertNotelinkCommand => new RelayCommand(InsertNotelink);
3638
public ICommand InsertMaillinkCommand => new RelayCommand(InsertMaillink);
@@ -247,7 +249,59 @@ private void LockUnlockNote()
247249
}
248250
}
249251

250-
private void AddTagToNote(string t)
252+
private void ExportFrontmatter()
253+
{
254+
if (SelectedNote == null) return;
255+
256+
var dialog = new VistaFolderBrowserDialog();
257+
if (!(dialog.ShowDialog() ?? false)) return;
258+
259+
try
260+
{
261+
var tnow = DateTime.UtcNow;
262+
263+
var directory = dialog.SelectedPath;
264+
foreach (var note in Repository.Notes)
265+
{
266+
var subpath = note.Path.Enumerate().Select(p => ANFilenameHelper.StripStringForFilename(p)).ToArray();
267+
268+
var filename = ANFilenameHelper.StripStringForFilename(note.Title) + ".md";
269+
270+
var filedir = Path.Combine((new string[] { directory }).AsEnumerable().Concat(subpath).ToArray());
271+
272+
Directory.CreateDirectory(filedir);
273+
274+
var filedest = Path.Combine((new string[] { directory }).AsEnumerable().Concat(subpath).Concat(new string[] { filename }).ToArray());
275+
276+
var mdfm = "---\n";
277+
mdfm += $"id: {note.UniqueName}\n";
278+
mdfm += $"title: {note.Title}\n";
279+
mdfm += $"updated: {note.ModificationDate.ToUniversalTime():yyyy-MM-dd HH:mm:ss}Z\n";
280+
mdfm += $"created: {note.CreationDate.ToUniversalTime():yyyy-MM-dd HH:mm:ss}Z\n";
281+
mdfm += $"exported: {tnow.ToUniversalTime():yyyy-MM-dd HH:mm:ss}Z\n";
282+
mdfm += $"locked: {note.IsLocked.ToString().ToLower()}\n";
283+
mdfm += $"pinned: {note.IsPinned.ToString().ToLower()}\n";
284+
mdfm += $"conflict: {note.IsConflictNote.ToString().ToLower()}\n";
285+
mdfm += $"tags: [{string.Join(", ", note.Tags.Select(p => '"' + HttpUtility.JavaScriptStringEncode(p) + '"'))}]\n";
286+
mdfm += $"path: [{string.Join(", ", note.Path.Enumerate().Select(p => '"' + HttpUtility.JavaScriptStringEncode(p) + '"'))}]\n";
287+
mdfm += $"---\n";
288+
mdfm += $"\n";
289+
mdfm += note.Text;
290+
291+
if (File.Exists(filedest)) { throw new Exception($"File {filedest} already exists"); }
292+
293+
File.WriteAllText(filedest, mdfm, Encoding.UTF8);
294+
}
295+
}
296+
catch (Exception e)
297+
{
298+
App.Logger.Error("Main", "Could not write to file", e);
299+
ExceptionDialog.Show(Owner, "Could not write to file", e, string.Empty);
300+
}
301+
}
302+
303+
304+
private void AddTagToNote(string t)
251305
{
252306
if (SelectedNote == null) return;
253307
if (Settings.IsReadOnlyMode) return;

Source/AlephNote.Common/Shortcuts/IShortcutHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public interface IShortcutHandler
1717
ICommand DuplicateNoteCommand { get; }
1818
ICommand PinUnpinNoteCommand { get; }
1919
ICommand LockUnlockNoteCommand { get; }
20-
ICommand InsertHyperlinkCommand { get; }
20+
ICommand ExportFrontmatterCommand { get; }
21+
ICommand InsertHyperlinkCommand { get; }
2122
ICommand InsertFilelinkCommand { get; }
2223
ICommand InsertNotelinkCommand { get; }
2324
ICommand InsertMaillinkCommand { get; }

Source/AlephNote.Common/Shortcuts/ShortcutManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static ShortcutManager()
5555
AddCommand(ASS.Window, "DuplicateNote", h => h.DuplicateNoteCommand, "Create a new note as a copy of the current note", ActionModifier.AccessControl);
5656
AddCommand(ASS.Window, "PinUnpinNote", h => h.PinUnpinNoteCommand, "Pin the note to the top (or un-pin the note)", ActionModifier.AccessControl);
5757
AddCommand(ASS.Window, "LockUnlockNote", h => h.LockUnlockNoteCommand, "Lock/Unlock the note (prevent editing)", ActionModifier.AccessControl);
58+
AddCommand(ASS.Window, "ExportFrontmatter", h => h.ExportFrontmatterCommand, "Export all notes as markdown files");
5859

5960
AddCommand(ASS.NoteEdit, "InsertHyperlink", h => h.InsertHyperlinkCommand, "Insert a Hyperlink", ActionModifier.AccessControl);
6061
AddCommand(ASS.NoteEdit, "InsertFilelink", h => h.InsertFilelinkCommand, "Insert a link to a local file", ActionModifier.AccessControl);

0 commit comments

Comments
 (0)