Obsidianでノートの内容をGeminiに要約してもらい、descriptionに設定するTemplater
APIキーは以下で取得可能
(たぶん、プロジェクトの作成が必要で、テキトーに作ればいい)
(以下、実際はmdファイルだが、シンタックスを使うためjsにしてある)
code:_setDescription.js
<%*
const api_key = ''
const prompt = "<title>と<content>を合わせて簡潔に要約し、descriptionに設定できるような一文にしてください。"//自由に書き換えてよい
if(!prompt) return
const title = tp.file.title
const content = tp.file.content
text = <title>${title}</title><content>${content}</content>\n:${prompt}
new Notice("thinking...")
const data = {
contents: [{
parts: text: text }
}]
}
response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-goog-api-key': api_key
},
body: JSON.stringify(data)
})
if(response.ok) {
const result = await response.json()
new Notice("プロパティに設定")
s = result.candidates0.content.parts0.text //ここにGeminiからの回答が入っている const file = tp.file.find_tfile(tp.file.path(true)); // フロントマターを処理・更新
await app.fileManager.processFrontMatter(file, (frontmatter) => {
});
}else{
new Notice(response.statusText)
}
%>