これが直接言及しているわけではないが、確かにObsidian Linterにpost script的な機能はありそうThat plugin hasn't been updated in a while and seems to have a major bug. Linter may be a better choice for an out-of-the-box solution.
<%*
// Front matterのキー
const KEY = 'updated'
// 値の日時フォーマット
const date = tp.date.now("YYYY-MM-DD")
const UPDATED = `${KEY}: ${date}`
const editor = app.workspace.activeLeaf.view.editor
const updatedFrontMatter = tp.frontmatter.updated
if (updatedFrontMatter) {
const index = await tp.user.replace_line_at_word_starts(KEY + ": ", UPDATED)
if (index !== undefined) {
new Notice("最終更新日を更新しました")
} else {
new Notice("最終更新日を更新しようとしましたが失敗しました")
}
return
}
const frontMatterBody = `
created: ${date}
${KEY}: ${date}
`.trim()
const hasFrontMatter = Object.keys(tp.frontmatter).length > 0
if (hasFrontMatter) {
await tp.user.insert_new_line_at_word_found("---", frontMatterBody)
return
}
const noteBody = `---
${frontMatterBody}
---
`
await tp.user.insert_new_line_at_first(noteBody)
%>