這則筆記是Youtube影片用七個範例,學會最實用的dataview篩選語法!的教學講義,請與影片搭配使用。

Obsidian dataview實作篇・下(新增檢視模式)

A. 用econtains篩選選擇題(list type)的特定選項:找出所有「實體書」

and econtains(閱讀狀態, "實體書")

econtains適合用來篩選特定list type選項,算是最常用到的篩選語法!

B. 用「 and 」「or」「()」組合多個條件:找出所有「電子書」

and (
	econtains(持有狀態, "Kindle") or
	econtains(持有狀態, "讀墨") or
	econtains(持有狀態, "圖書館-HyRead")
	)
  • and = 取交集
  • or = 取聯集
  • () = 括弧內優先運算

C. 根據閱讀狀態篩選(跟A. 的原理一模一樣)

D. 否定的用法:找出「即將第一次閱讀」的書

  • 否定:條件前加上 ! 或者條件後加上 =false
  • 即將第一次閱讀的書的定義:「閱讀狀態」欄位中,有「想讀」這個選項,但是沒有「讀完」這個選項。

E. 找出「未分類」的書

and !書本類別
  • 代表「書本類別」欄位為「空」
  • =false 在這裡則不適用

F. 列出最近使用過的n本書

默認欄位 Implicit Field

  • file.mtime 上次修改時間
  • file.mday 上次修改日期

Sort & Limit

SORT file.mtime DESC
LIMIT 5
  • DESC = 降冪排列
  • ASC = 升冪排列

AS更改欄位顯示名稱

table file.mday AS 上次使用

Bonus - minimal cards (Obsidian Snippets)

snippet開啟的狀態下,在檔案的front matter中加入cssclasses: cards, cards-cols-2 之類的指令,就可以把dataview table變成一張張的卡片。

snippet下載點: https://github.com/kepano/obsidian-minimal/blob/master/src/scss/features/cards.scss 要自行把scss轉檔成css才能使用 → 影片資訊欄有分享已經轉好檔的css檔案,請參考。

Cards的用法官方說明: https://minimal.guide/cards

ClassDescription
cardsSet all Dataview tables to card layout
list-cardsSet all bullet lists to card layout
table-100Cards block fills 100% of the pane width
table-maxCards block fills the max line width
table-wideCards block fills the wide line width
cards-align-bottomAlign the last element of a card to the bottom
cards-coverImages are resized to fill the defined space
cards-16-9Fit images in cards to 16:9 ratio
cards-1-1Fit images in cards to 1:1 ratio (square)
cards-2-1Fit images in cards to 2:1 ratio
cards-2-3Fit images in cards to 2:3 ratio
cards-cols-1 to 8Force a specific number of columns (from 1 to 8)