基本信息
原始卡片::[[dataview-dataview]] 卡片盒
需求::快速查询和聚类笔记,形成自己的数据库
- 在正文中可以用:
::
两个冒号进行属性的赋值 - 正文中增加: `= this.file.name` 就可以直接使用daview查询语句
- 注释代码: //
- 帮助文档::Data Annotation - Dataview
- without id 隐藏第一列
- 发布的话,不能发布内容,只能发布代码出去
- limit 100 来限制输出的内容
- 基本语法如下:
[list|table|task] field1, (field2 + field3) as myfield, ..., fieldN
from #tag or "folder" or [[link]] or outgoing([[link]])
where field [>|>=|<|<=|=|&|'|'] [field2|literal value] (and field2 ...) (or field3...)
sort field [ascending|descending|asc|desc] (ascending is implied if not provided)
2 名人案例
- An Introduction to Dataview Slides
- 可能在ob会用一辈子的dataview代码
- Obsidian DataView 入门保姆级引导手册 - 知乎
- 使用Dataview进行书籍管理
3 元数据
3.1 文件
dataview能自动的对每个页面添加大量的元数据。
file.name
: 该文件标题(字符串)。file.folder
: 该文件所在的文件夹的路径(字符串)。file.path
: 该文件的完整路径(字符串)。file.link
: 该文件的一个链接(链接)。file.size
: 该文件的大小(bytes)(数字)file.ctime
: 该文件的创建日期(日期和时间)。file.cday
: 该文件的创建日期(仅日期)。file.mtime
: 该文件最后编辑日期(日期和时间)。file.mday
: 该文件最后编辑日期(仅日期)。file.tags
: 笔记中所有标签组成的数组。子标签按每个级别进行细分,所以#Tag/1/A
将会在数组中储存为[#Tag, #Tag/1, #Tag/1/A]
。file.etags
: 笔记中所有显式标签组成的数组;不同于file.tags
,不包含子标签。file.outlinks
: 该文件所有外链(outgoing link)组成的数组。file.aliases
: 笔记中所有别名组成的数组。without id
:不显示默认的链接- 如果文件的标题内有一个日期(格式为yyyy-mm-dd或yyyymmdd),或者有一个Date字段/inline字段,它也有以下属性:
file.day
: 一个该文件的隐含日期。
3.2 任务
As with pages, Dataview adds a number of implicit fields to each task: 与页面一样,Dataview为每个任务添加了一些隐式字段:
tasks inherit all fields from their parent page - so if you have a rating field in your page, you can also access it on your task.
任务从其父页面继承所有字段,因此,例如您的页面中有一个评级字段,您也可以在任务中访问它。
- compleTED: Whether or not this specific task has been completed; this does not consider the completion/non-completion of any child tasks.
- 已完成:此特定任务是否已完成;这不考虑任何子任务的完成/未完成。
- fullyCompleted: Whether or not this task and all of its subtasks are completed.
- 完全完成:此任务及其所有子任务是否完成。
- text: The text of this task.
- text:此任务的文本。
- line: The line this task shows up on.
- line:此任务显示的行。
- path: The full path of the file this task is in.
- path:此任务所在文件的完整路径。
- section: A link to the section this task is contained in.
- 部分:指向包含此任务的部分的链接。
- link: A link to the closest linkable block near this task; useful for making links which go to the task.
- 链接:指向该任务附近最近的可链接块的链接;用于创建指向该任务的链接。可以通过手动块的形式添加链接,
- subtasks: Any subtasks of this task.
- 子任务:此任务的任何子任务。
- real: If true, this is a real task; otherwise, it is a list element above/below a task.
- real:如果为true,这是一个真正的任务;否则,它是一个任务上面/下面的列表元素。
- completion: The date a task was completed. If not annotated, will default to file modified time.
- 完成:任务完成的日期。如果没有注释,将默认为文件修改时间。
- due: The date a task is due, if it has one.
- 到期日:任务的到期日(如果有的话)。
- created: The date a task was created. If not annotated, defaults to file creation time.
- 已创建:任务创建的日期。如果未加注释,则默认为文件创建时间。
- annotated: True if the task has any custom annotations, and false otherwise.
- 注释:如果任务有任何自定义注释,则为true,否则为false。
4 符号
4.1 \反斜杠可以避免进行双链转义
table without id file.link as 笔记名称,aliases as 别名, "\[["+file.name+"|"+aliases+"]]" as 别名组合, postId as 发布ID ,"https://www.weqoocu.com/"+postId+".html" as url , dateformat(file.mtime,"yyyy-MM-dd") as 修改时间
WHERE number(postId)>0 and profileName="Default" AND length(aliases)>0
Sort number(postId) desc
5 函数
5.1 length(rows) group by
table length(rows) as 数量
from "9文献笔记/wu"
WHERE icontains(file.name,"wucai") and !icontains(url,"wucainote") and length(全域名)>1
group by 全域名
sort length(rows) desc
5.2 length
判断某个字符的长度
table without id file.link as 笔记名称,aliases as 别名, postId as 发布ID ,"https://www.weqoocu.com/"+postId+".html" as url , dateformat(file.mtime,"yyyy-MM-dd") as 修改时间
WHERE number(postId)>0 and profileName="Default" AND length(aliases)>0 AND file.mtime>date("2023-09-15")
Sort number(postId) desc
6 常用代码
7 JS 案例
7.1 获取 fn文件夹下, ## 正文 下的内容, 按照 编码 排序
//输入目标小标题(含#),例如:## 正文
const header = '## 正文'
// 按【路径或文件夹、文件名、标签】筛选并按修改时间降序排列
const pages = dv.pages('[[滴答清单]]').filter(p => p.file.name.includes("") && p.file.path.includes("fn")).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(2, '[[' + file.basename + ']]')
dv.PARAgraph(summary[1].trim())
}
}
输出标签带链接:dv.header(4, '[['+ file.basename + '|'+page.编码+' '+page.需求+']]')
输出的内容不带链接: dv.header(3, page.编码+' '+page.需求)
7.2 标题不需要链接
//输入目标小标题(含#),例如:## 项目进度条
const header = '## 正文'
// 按【路径或文件夹、文件名、标签】筛选并按修改时间降序排列
const pages = dv.pages('[[大模型]]').filter(p => p.file.name.includes("") && p.file.path.includes("fn")).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(4, '[['+ file.basename + '|'+page.编码+' '+page.需求+']]')
//或者dv.header(2, '[[' + file.basename + ']]')
dv.paragraph(summary[1].trim())
}
}
8 DQL案例
9 已编码卡片
table without id 编码,需求 as 卡片 ,正文,"[["+file.name+"|详情]]" as 笔记详情
from [[<% tp.file.title %>]] and ![[个人词条]] and ![[五彩]] and -#MOC and -#dataview and "9文献笔记/fn"
where number(编码)>0
sort number(编码)
9.1 根据标签检索文章
table without id dateformat(file.ctime,"yyyy-MM-dd") as 时间, 需求 as 互动记录,"[["+file.name+"|详情]]" as 笔记详情
from ![[个人词条]] and ![[五彩]] and "9文献笔记"
where icontains(file.tags,"<% tp.file.title %>")
sort 类型,file.ctime desc
9.2 设置链接
"["+标题+"]("+url+")" as 官网
9.3 域名判断
where icontains(母域名,"xiaohongshu.com")
9.4 详情
"[["+file.name+"|详情]]" as 详情
9.5 五彩笔记
Table without id "["+标题+"]("+file.name+")" as 标题,file.size as 字数,file.mtime as 修改时间,file.outlinks as 外链,highlightcount as 划线数, pagenote as 页面笔记,pagemirror as 全文剪藏
From "9文献笔记/wu"
where file.name!="wucai-2023-07-03-H8ADHKA"
Sort file.mtime desc
limit 10
9.6 没有阅读的小红书
table without id "["+标题+"]("+url+")" as 标题,file.link as 笔记名字,file.outlinks
WHERE icontains(母域名,"xiaohongshu.com") and length(file.outlinks)=1
sort file.ctime desc
9.7 没有重复的7天内完成的任务
task
from !#重复
where !completed and due!=null and due - date(today) <= dur(7 days)
Sort due
9.8 没有完成时间的任务
task
where !completed and due=null
9.9 聊天记录
Table without id file.link,标题,file.outlinks
From "9文献笔记/wu"
WHERE contains(标题,"Note")
Sort file.mtime desc
limit 10
9.10 可以通过关键词去检索全部中特点关键词的内容,这个脚本非常不错
dataviewjs
//全库检索//慎用//文件太多可能会卡
//使用时修改关键词即可
//输出全库带有关键词的段落
//呈现文本格式
const term = "DIKW"
const files = app.vault.getMarkdownFiles()
const arr = files.map(async ( file) => {
const content = await app.vault.cachedRead(file)
const lines = content.split("\n").filter(line => line.contains(term))
return lines
})
Promise.all(arr).then(values =>
dv.list(values.flat()))
9.11 支持时间判断
table without id file.link as 主题名称, postId as 发布ID ,"https://www.weqoocu.com/"+postId+".html" as url , dateformat(file.mtime,"yyyy-MM-dd") as 修改时间
WHERE number(postId)>0 and dateformat(file.mtime,"yyyy-MM-dd") > "2023-08-18"
Sort file.mtime desc
9.12 拼接内容:比如网站地址
"https://www.weqoocu.com/"+postId+".html" as url
9.13 查找链接或者反向链接某个笔记的笔记
from outgoing([[睡眠]]) OR [[睡眠]]
9.14 将字段数字化,变为大于零
table postid as "发布id"
WHERE number(postId)>0
Sort file.mtime desc
limit 10
9.15 使用函数转换日期:dateformat(file.ctime,"yyyy-MM-dd")
dataview
table dateformat(file.ctime,"yyyy-MM-dd") as"时间" from "1 知识管理"
sort file.ctime desc limit 50
9.16 常用的组合
list from #A and #B
list from "University" or "Work"
list from -#Personal
list from [[CSS]] and -#HTML
9.17 排除某个文件
where file.name != "2021-04-09 Daily Note"
9.18 排除标签
-#Personal
9.19 展示
file.outlinks
9.20 读取文件标题含有特定字符的
Table without id file.link,file.outlinks
From "9文献笔记/wu" and -#moc
Sort file.outlinks
WHERE icontains(标题,"Daily")
limit 10
9.21 支持文件名过滤
table without id 标题,url,全域名,母域名,file.link
from [[新产品体验]]
WHERE icontains(file.name,"wucai")
sort file.mtime desc
使用的[[yaml]],在介绍使用之前,我们简单的了解下Dataview的语法
# 当前文件中未完成的任务
table file.name as "文件名", length(filter(file.tasks, (t) => !t.completed)) as "未完成任务数"
from ""
WHERE !completed
WHERE file.name = this.file.name
```dataview
table
from #moc
sort file.name asc
```dataview
list
from #1-0智慧/思维模型/系统思考 and "9文献笔记"
sort file.name asc
# 待办清单
```dataview
task
WHERE !completed
GROUP BY file.name
sort file.name asc
修改的卡片
list
where file.mday=date(today)
sort file.name asc
``
list
from #1-0智慧/思维模型/系统思考 and ("5卡片盒" or "1索引")
sort file.name asc
table file.tags as 标签,file.inlinks as 引用地址,file.outlinks as 流向地址
from #1-0智慧/思维模型/卡片盒笔记法
sort file.name asc
今天创建的卡片
list
where file.cday=date(this.file.cday)
sort file.name asc
推荐文章
- 五彩 (0.877)
- obsidian-插件-auto-Note-Mover (0.877)
- thino (0.877)
- obsidian-插件-wordpress (0.877)
- obsidian插件-douban (0.877)
- 清单-人物-四大美女 (RANDOM - 0.500)