基本信息
- 需求::模板插件,配合/或者obsidian-editing-toolbar可以快速输入
- 帮助中心::Moment.js | Docs
- github::SilentVoid13/Templater: A template plugin for obsidian
- 帮助中心::Introduction - Templater
- 简介::为obsidan提供模版功能
快速创建dataview和选中关键词的
- <% tp.file.title.split('_')[0] %>: 取空格标题空格前面的字符
- <% tp.file.title.trimStart().split(‘ ’)[0] %>:trimStart()用于防止文件标题开头有空格,如果没有问题则忽略它。
选中文本创建:dataview
-
[[<% (await tp.file.create_new(tp.file.find_tfile("dataview-templater"),"dataview-"+tp.file.selection())).basename %>]]
-
<% tp.file.title.split("-")[1] %> :取值 分隔符 - 后面的第二个值
通过提示框建立:dataview
- [[<% (await tp.file.create_new(tp.file.find_tfile("dataview-templater"),"dataview-"+ (await tp.system.prompt("请输入要创建的文件名")) )).basename %>]]
常用代码
- 指定鼠标的位置:
- 今天的时间:<% tp.date.now("YYYY-MM-DD")%> , 前一天:<% tp.date.now("YYYY-MM-DD", -1) %>
插入文章来源的模版代码
文章来源:bc16f783-e009-4e0d-9db1-f685aeee3098
修改卡片盒聚合的代码
原
table without id 编码,file.folder as 路径,需求 as 卡片 ,"[["+file.name+"|详情]]" as 详情,"[五彩]("+wucai_url+")" as 五彩
from [[undefined]] and ![[个人词条]] and -[[官网]] and -[[迭代记录]] and -[[博客]] and -[[下载]] and -#MOC and -#dataview and "9文献笔记"
where number(编码)<0 and !icontains(source,"chromewebstore")
sort file.folder
修改为
table without id 编码,file.folder as 路径,需求 as 卡片 ,"[["+file.name+"|详情]]" as 详情,"[五彩]("+wucai_url+")" as 五彩
from ![[个人词条]] and -[[官网]] and -[[迭代记录]] and -[[博客]] and -[[下载]] and -#MOC and -#dataview and "9文献笔记"
where number(编码)<0 and !icontains(source,"chromewebstore") and icontains(string(产品),"undefined]]")
sort file.folder
原脚本:
//输入目标小标题(含#),例如:## 项目进度条
const header = '## 正文'
// 按【路径或文件夹、文件名、标签】筛选并按修改时间降序排列
const pages = dv.pages('[[undefined]]').filter(p => p.file.name.includes("") && p.file.path.includes("文献笔记")).filter(p => p.file.name.includes("") || p.file.name.includes("")).sort(p=>p.编码,"asc");
// This regex will return text from the Summary header, until it reaches
// the next header, a horizontal line, or the end of the file
const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')
for (const page of pages) {
const file = app.vault.getAbstractFileByPath(page.file.path)
// Read the file contents
const contents = await app.vault.read(file)
// Extract the summary via regex
const summary = contents.match(regex)
//显示全部包括空结果if (summary) {
//不显示空结果if (summary && summary[1].trim()) {
if (summary && summary[1].trim()) {
// Output the header and summary
//dv.header(3, '[['+ file.basename + '|'+page.编码+' '+page.需求+']]')
dv.header(3, page.编码+' '+page.需求)
//或者dv.header(2, '[[' + file.basename + ']]')
dv.PARAgraph(summary[1].trim())
}
}
修改为:
//输入目标小标题(含#),例如:## 项目进度条
const header = '## 正文';
// 按【路径或文件夹、文件名、标签】筛选并按修改时间降序排列
// 注意:这里应该是按照某个字段排序,但'编码'需要是页面的一个属性。
// 如果'编码'是页面的一个字段,应确保它是已定义的。否则,排序可能不会正常工作。
// 另外,原代码中的排序是升序("asc"),如果需要降序,应改为"desc"。
// 由于您之前要求的是按照'编码'升序排列,这里保持为'asc'。
const pages = dv.pages('"9文献笔记"').filter(b => b.产品?.path == '5卡片盒/undefined.md').sort(p => p.编码, "asc");
// This regex will return text from the Summary header, until it reaches
// the next header, a horizontal line, or the end of the file
const regex = new RegExp(`\\n${header.replace(/#/g, '\\#')}\\r?\\n(.*?)(\\n#+ |\\n---|$)`, 's');
let fulltext = ''; // 初始化fulltext为空字符串
for (const page of pages) {
const file = app.vault.getAbstractFileByPath(page.file.path);
// Read the file contents
const contents = await app.vault.read(file);
// Extract the summary via regex
const match = contents.match(regex);
if (match && match[1].trim()) {
// 显示页面内容
dv.header(3, page.编码 + ' ' + page.需求);
dv.PARAgraph(match[1].trim());
// 同时将内容添加到fulltext
fulltext += `## ${page.编码} ${page.需求}\n${match[1].trim()}\n\n`;
}
}
// 复制到剪贴板
if (navigator.clipboard) {
navigator.clipboard.writeText(fulltext)
.then(() => console.log('Text copied to clipboard'))
.catch(err => console.error('Error in copying text: ' + err));
} else {
console.error('Clipboard API not available');
}
修改来源插入模板,增加跳转到ob的入口
在深圳回成都的路上,发现可以快速在阅读文章的时候,跳转到ob进行编辑。就修改了来源模板如下,测试没有问题。
文章来源:58a33f66-f952-4747-a0e8-1283b3aadea4
编辑笔记:OB链接
推荐文章
- 8.1.20250715 Obsidian插件实现YAML标题更新 (0.873)
- 5.3.202504obsidian-插件-wordpress:发布obsidian笔记到WordPress (0.702)
- 5.1.1应用-知识管理工具-五彩插件 (0.702)
- 5.3.1obsidian插件-components (0.702)
- 5.3.202504 obsidian插件-Front-Matter-Title (0.702)
- 5应用-效率工具-搜狗输入法 (RANDOM - 0.500)