<% await tp.user.date(tp) %>
Last active
December 13, 2022 18:15
-
-
Save mnaoumov/faf6a11de7e64de31a5e5ac5a2feba53 to your computer and use it in GitHub Desktop.
Obsidian Templater date creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = async (tp, notePath, noteContent, includeDefaultHeader = true) => { | |
if (await tp.file.exists(notePath)) { | |
return; | |
} | |
const title = notePath.split('/').pop().replace('.md', ''); | |
const nowStr = moment().format('YYYY-MM-DD-HH-mm-ssZ'); | |
const fullNoteContent = includeDefaultHeader ? `--- | |
title: '${title}' | |
created: ${nowStr} | |
updated: ${nowStr} | |
--- | |
# ${title} | |
${noteContent}` : noteContent; | |
await tp.file.create_new(fullNoteContent, notePath, false, app.vault.getAbstractFileByPath('/')); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = async (tp, dateStr) => { | |
if (dateStr === undefined) { | |
dateStr = await tp.system.prompt('Enter date (YYYY-MM-DD)'); | |
} | |
const date = moment(dateStr, 'YYYY-MM-DD', true); | |
if (!date.isValid()) { | |
return `!!! ${dateStr} is not a valid YYYY-MM-DD date !!!`; | |
} | |
const dateNotePath = date.format('/[Dates]/YYYY/YYYY-MM/YYYY-MM-DD[.md]'); | |
await tp.user.createNoteIfMissing(tp, dateNotePath, `\`\`\`dataviewjs | |
dv.view('../../!dataview'); | |
\`\`\` | |
`); | |
await tp.user.createNoteIfMissing(tp, date.format('/[Dates]/YYYY/YYYY-MM/YYYY-MM[.md]'), `\`\`\`dataviewjs | |
dv.view('../../!dataview'); | |
\`\`\` | |
`); | |
await tp.user.createNoteIfMissing(tp, date.format('/[Dates]/YYYY/YYYY[.md]'), `\`\`\`dataviewjs | |
dv.view('../!dataview'); | |
\`\`\` | |
`); | |
return app.fileManager.generateMarkdownLink(tp.file.find_tfile(dateNotePath), tp.config.target_file.path); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment