From 32e76d79884e9be8dbbc88dbd01ac3903e0525bb Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Mon, 8 Jan 2024 03:59:44 -0800 Subject: [PATCH] Desktop: Resolves #9683: Frontmatter importer: Support Notesnook-style timestamps (#9684) --- .../support/test_notes/yaml/notesnook_updated_created.md | 9 +++++++++ .../InteropService_Importer_Md_frontmatter.test.ts | 7 +++++++ .../interop/InteropService_Importer_Md_frontmatter.ts | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 packages/app-cli/tests/support/test_notes/yaml/notesnook_updated_created.md diff --git a/packages/app-cli/tests/support/test_notes/yaml/notesnook_updated_created.md b/packages/app-cli/tests/support/test_notes/yaml/notesnook_updated_created.md new file mode 100644 index 000000000..6b432f185 --- /dev/null +++ b/packages/app-cli/tests/support/test_notes/yaml/notesnook_updated_created.md @@ -0,0 +1,9 @@ +--- +title: "Frontmatter test" +created_at: 01-01-2024 01:23 AM +updated_at: 02-01-2024 04:56 AM +--- + +# Frontmatter test + +A test note with frontmatter. diff --git a/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.test.ts b/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.test.ts index 8aaa18b22..cd8dc11b3 100644 --- a/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.test.ts +++ b/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.test.ts @@ -140,6 +140,13 @@ describe('InteropService_Importer_Md_frontmatter: importMetadata', () => { expect(note.title).toBe('Distill for R Markdown'); expect(note.author).toBe('JJ Allaire'); }); + it('should import Notesnook files with created and update timestamps', async () => { + const note = await importTestFile('notesnook_updated_created.md'); + + expect(note.title).toBe('Frontmatter test'); + expect(note.user_created_time).toBe(Date.parse('2024-01-01T01:23:00.000')); + expect(note.user_updated_time).toBe(Date.parse('2024-01-02T04:56:00.000')); + }); it('should handle date formats with timezone information', async () => { const note = await importTestFile('utc.md'); diff --git a/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.ts b/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.ts index 5711d2417..2477e6953 100644 --- a/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.ts +++ b/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.ts @@ -111,6 +111,9 @@ export default class InteropService_Importer_Md_frontmatter extends InteropServi metadata['user_created_time'] = time.anythingToMs(md['created'], Date.now()); } else if ('date' in md) { metadata['user_created_time'] = time.anythingToMs(md['date'], Date.now()); + } else if ('created_at' in md) { + // Add support for Notesnook + metadata['user_created_time'] = time.anythingToMs(md['created_at'], Date.now()); } if ('updated' in md) { @@ -120,6 +123,9 @@ export default class InteropService_Importer_Md_frontmatter extends InteropServi metadata['user_updated_time'] = time.anythingToMs(md['lastmod'], Date.now()); } else if ('date' in md) { metadata['user_updated_time'] = time.anythingToMs(md['date'], Date.now()); + } else if ('updated_at' in md) { + // Notesnook + metadata['user_updated_time'] = time.anythingToMs(md['updated_at'], Date.now()); } if ('latitude' in md) { metadata['latitude'] = md['latitude']; }