ObsidianのTemplaterで文字数をカウントしフロントマターに反映させる
code:sample.js
<%*
s = tp.file.selection();
if(s){
new Notice(...s.length + "文字です");-%> <% s %><%* }else{
s = tp.file.content;
new Notice(...s.length + "文字だよ"); //ここまで文字数の表示
//ここからフロントマターの更新
const counts = ...s.length; tp.hooks.on_all_templates_executed(async () => {
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
});
});
}-%>