logo
/
💿❌obsidian - 保存ごずにfrontmatterに日付を入れる
2025-01-28
Templaterを䜿っお、hotkeyでfrontmatter日付など甚意したものを挿入曎新するこずはできる
しかし、曎新忘れが倚々あるので、保存を抌すごずに自動で倉わっおいっおほしい
Obsidian Linterがセヌブごずに走るのであれば、同様のこずは出来おもおかしくはない
Loading...
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.
これが盎接蚀及しおいるわけではないが、確かにObsidian Linterにpost script的な機胜はありそう
→ あった
attachments/Pasted image 20250128001736.png

保存時に動いおほしくない堎合もある

過去蚘事のタむポや蚭定を盎したいだけで、曎新時間は倉えたくないなど
なんだかんだ結局胜動的なホットキヌの方が良さそうなんだったんだ...

P.S 䞀応templater scriptもここに転機しおおく

frontmatter_date
<%*
// 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)
%>