diff --git a/main.ts b/main.ts index 587f996..eb8a228 100644 --- a/main.ts +++ b/main.ts @@ -19,7 +19,7 @@ export default class PAUL extends Plugin { if (activeFile && activeFile.extension === 'md') { this.app.vault.read(activeFile).then(content => { const pattern = /Modified: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/; - let digit = (inp)=>{ return String(inp).padStart(2, '0') } + const digit = (inp: number)=>{ return String(inp).padStart(2, '0') } const t = new Date() const modified = `Modified: ${t.getFullYear()}-${digit(t.getMonth()+1)}-${digit(t.getDate())}T${digit(t.getHours())}:${digit(t.getMinutes())}:${digit(t.getSeconds())}Z`; @@ -32,6 +32,10 @@ export default class PAUL extends Plugin { const analysis = content.match(/^---\n((?!-{3})(?:(?:.+:.*)|(?:\s{2}-\s.+))\n)+---/); // const analysis = content.match(/---\n(.*:.*\n)*---/s); // console.log(analysis); + // frontmatter가 없으면 삽입할 위치를 찾을 수 없으므로 중단 + if (!analysis || analysis.index === undefined) { + return; + } const pnt = analysis.index + analysis[0].length - 3; this.app.vault.modify(activeFile, content.slice(0, pnt) + modified + '\n' + content.slice(pnt)); } diff --git a/package.json b/package.json index 6a00766..1808666 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "obsidian-sample-plugin", - "version": "1.0.0", + "name": "obsidian-modified-time-updater", + "version": "1.1.0", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/tsconfig.json b/tsconfig.json index 2d6fbdf..d7c8e6a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,8 @@ "DOM", "ES5", "ES6", - "ES7" + "ES7", + "ES2017" ] }, "include": [