Skip to content

Commit

Permalink
get things working and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
kortina committed Aug 25, 2020
1 parent 028a922 commit b44e172
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/NoteWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ export class NoteWorkspace {
return !!this.cfg().createNoteOnGoToDefinitionWhenMissing;
}


static compileSuggestionDetails(): boolean {
return this.cfg().compileSuggestionDetails;
}
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/jest/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit b44e172

Please sign in to comment.