From b44e1726eab79e72afc2357760ae3c4b55efcb0a Mon Sep 17 00:00:00 2001 From: Kortina Date: Mon, 24 Aug 2020 20:55:07 -0700 Subject: [PATCH] get things working and update test --- package-lock.json | 2 +- package.json | 4 ++-- src/NoteWorkspace.ts | 6 ++++-- src/test/jest/extension.test.ts | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c09cf9a..dfbe1ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-markdown-notes", - "version": "0.0.15", + "version": "0.0.17", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1d4ab0b..fd39189 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-markdown-notes", "displayName": "Markdown Notes", "description": "Navigate notes with [[wiki-links]], backlinks, and #tags (like Bear, Roam, etc). Automatically create notes from new inline [[wiki-links]]. Use Peek Definition to preview linked notes.", - "version": "0.0.17", + "version": "0.0.18", "publisher": "kortina", "repository": { "url": "https://github.com/kortina/vscode-markdown-notes.git", @@ -98,7 +98,7 @@ "vscodeMarkdownNotes.newNoteTemplate": { "type": "string", "default": "# ${noteName}\n\n", - "description": "Template for auto-created note files. Available tokens: ${noteName}, ${timestamp}. Timestamp is inserted in ISO format, i.e. 2020-07-09T05:29:00.541Z." + "description": "Template for auto-created note files. Available tokens: ${noteName}, ${timestamp}, ${date}. Timestamp is inserted in ISO format, i.e. 2020-07-09T05:29:00.541Z. Date is YYYY-MM-dd format." }, "vscodeMarkdownNotes.compileSuggestionDetails": { "type": "boolean", diff --git a/src/NoteWorkspace.ts b/src/NoteWorkspace.ts index 09e28cb..ee90165 100644 --- a/src/NoteWorkspace.ts +++ b/src/NoteWorkspace.ts @@ -201,7 +201,6 @@ export class NoteWorkspace { return !!this.cfg().createNoteOnGoToDefinitionWhenMissing; } - static compileSuggestionDetails(): boolean { return this.cfg().compileSuggestionDetails; } @@ -400,10 +399,13 @@ export class NoteWorkspace { static newNoteContent(noteName: string) { const template = NoteWorkspace.newNoteTemplate(); + const d = (new Date().toISOString().match(/(\d{4}-\d{2}-\d{2})/) || '')[0]; // "2020-08-25" + const t = new Date().toISOString(); // "2020-08-25T03:21:49.735Z" const contents = template .replace(/\\n/g, '\n') .replace(/\$\{noteName\}/g, noteName) - .replace(/\$\{timestamp\}/g, new Date().toISOString()); + .replace(/\$\{timestamp\}/g, t) + .replace(/\$\{date\}/g, d); return contents; } diff --git a/src/test/jest/extension.test.ts b/src/test/jest/extension.test.ts index cd146eb..818cc09 100644 --- a/src/test/jest/extension.test.ts +++ b/src/test/jest/extension.test.ts @@ -295,4 +295,13 @@ describe('NoteWorkspace.newNoteContent', () => { const date1 = Date.parse(matches![1]); expect(date1).not.toBe(Number.NaN); }); + + it('handles date', () => { + const template = '# Title\nDate: ${date}\n'; + + const content = newNote(template, 'nevermind'); + const d = (new Date().toISOString().match(/(\d{4}-\d{2}-\d{2})/) || '')[0]; + const dt = `Date: ${d}`; + expect(content.includes(dt)).toBeTruthy(); + }); });