网站导航

dataview

#obsidian #插件 #主题研究

1 基本信息

  • 帮助文档::Data Annotation - Dataview
  • without id 隐藏第一行
  • 导出的输出,只有原生的PDF是能显示内容的
  • 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 名人案例

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  "["+标题+"]("+url+")" as 标题,file.link as 笔记名字,file.outlinks

 

WHERE icontains(母域名,"xiaohongshu.com")  and length(file.outlinks)=1

sort file.ctime desc

4.2 没有重复的7天内完成的任务


task

from  !#重复

where !completed  and   due!=null and due - date(today) <= dur(7 days) 

Sort  due


#### 4.2 没有完成时间的任务

task

where !completed and due=null



#### 4.3 聊天记录

Table without id file.link,标题,file.outlinks
From "9文献笔记/wu"

WHERE contains(标题,"Note")
Sort file.mtime desc
limit 10


#### 4.4 可以通过关键词去检索全部中特点关键词的内容,这个脚本非常不错
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()))

#### 4.5 支持时间判断

table without id file.link as 主题名称, postId as 发布ID ,"http://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



#### 4.6 拼接内容:比如网站地址

`"http://www.weqoocu.com/"+postId+".html" as url`


#### 4.7 查找链接或者反向链接某个笔记的笔记

from outgoing([[睡眠]]) OR [[睡眠]]




#### 4.8 将字段数字化,变为大于零

table postid as "发布id"

WHERE number(postId)>0

Sort file.mtime desc

limit 10



#### 4.9 使用函数转换日期:dateformat(file.ctime,"yyyy-MM-dd")

dataview

table dateformat(file.ctime,"yyyy-MM-dd") as"时间" from "1 知识管理"

sort file.ctime desc limit 50





#### 4.10 常用的组合


list from #A and #B
list from "University" or "Work"
list from -#Personal
list from [[CSS]] and -#HTML



#### 4.11 排除某个文件


where file.name != "2021-04-09 Daily Note"



#### 4.12 排除标签

-#Personal


#### 4.13 展示

file.outlinks



#### 4.14 读取文件标题含有特定字符的

Table without id file.link,file.outlinks
From "9文献笔记/wu" and -#moc
Sort file.outlinks
WHERE icontains(标题,"Daily")
limit 10





使用的[[yaml]],在介绍使用之前,我们简单的了解下**Dataview**的语法




当前文件中未完成的任务

table file.name as "文件名", length(filter(file.tasks, (t) => !t.completed)) as "未完成任务数"

from ""

WHERE !completed

WHERE file.name = this.file.name





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