Obsidian v1.9.0新增了 Bases 核心外掛,它的功能是參照Notion的 Database,提供了資料集合的展現功能,非常適合收藏(Collections,蒐藏)類型的應用場合,例如書籍收藏、電影收藏、音樂收藏等。
這次我使用更貼切筆記管理的「筆記收藏」,使用 Bases 將原本以 Dataview 建立的索引筆記轉換為 Bases 的語法,從而讓大家能看到二者間的功能差異。
[!question] Base 應如何翻譯?
對應 Database(資料庫),譯成「庫」應該可行,但庫用得太多了(如Obsidian的vault、Git的repository),我傾向說成「資料集合」或「資料集」。
首先在設定(Settings)→核心外掛(Core Plugins)裡啟用Bases外掛,按Ctrl/Cmd+P在命令面板裡輸入「base」可找到兩個命令:
![[Untitled.base]]
,並自動建立 Untitled.base檔案Bases也提供了程式碼區塊的使用方法(YAML格式),例如:
```base
filters:
and:
- taggedWith(file.file, "book")
- not:
- taggedWith(file.file, "textbook")
formulas:
read_status: 'if(status == "Done", "Read", "Unread")'
reading_time: 'wordCount / 250'
display:
author: Author
formula.read_status: "Reading Status"
formula.reading_time: "Est. Reading Hours"
tags: Tags
priority: Priority
views:
- type: table
name: "Reading List"
filters: 'formula.read_status == "Unread"'
order:
- file.name
- author
- priority
- formula.reading_time
- type: gallery
name: "Book Gallery"
filters: 'formula.read_status == "Unread"'
title_field: file.name
description_field: summary
- type: board
name: "Reading Board"
group_by: "priority"
title_field: file.name
description_field: summary
- type: table
name: "Completed Books"
filters: 'formula.read_status == "Read"'
order:
- file.name
- author
- priority
- formula.reading_time
目標:建立含有
#obsidian
標籤的筆記清單以做為索引筆記
執行【Bases: Create new base】後,會在指定資料夾產生未命名.base(Untitled.base),並開啟在新分頁。
由左到右有檢視模式(Table)、資料筆數(3,230 results)、排序(Sort)、過濾(Filter)、屬性(Properties)等選項。
先點擊Filter變更過濾條件以減少資料筆數:下圖設定tags contains obsidian
將顯示含有#obsidian
標籤的筆記,生效後符合筆數由3230變成332。
點擊Properties以新增顯示欄位:勾選需要的屬性即可增添。
例如勾選YAML區裡的 created、modified與tags 等屬性。
特殊的欄位可以用Add formula新增公式,例如用公式 created.toString().slice(0, 10)
顯示 created (建檔時間)的日期部份。
一個Base能設定多個檢視樣式,不同的檢視能指定各自的佈局、過濾與欄位。目前Bases只支援兩種佈局:Table與Cards。
cover_image_url starts with http
。[!tip] Base的在地編輯
在Table檢視時,可直接修改欄位內容,修改的內容直接同步到該筆記。
點擊Sort或標題即可設定資料排序的形式。
點擊【筆數 results】可限制顯示筆數,也可匯出資料到剪貼簿或存成.csv檔案。
插入![[Untitled.base]]
,並建立Untitled.base檔案。
除非已經非常熟悉Bases的YAML語法,否則建議還是先用視覺化的話操作產生.base檔,再用文字編輯器開啟後,複製內容以產生Base程式碼區塊,程式碼語言是 base。
插入後,即可在Obsidian裡修改成自己需要的格式。
瀏覽Bases Toolbox,將Dataview TABLE敘述貼入Dataview Converter分頁,再點擊Convert to Bases就能立即轉換。
我使用的一個Dataview顯示建檔日期(Property: created)開頭的10個字元,即只顯示日期而不顯示時間:substring(created, 0, 10)
,導致Bases出現錯誤,修改如下:
created.toString().slice(0, 10)
[!tip] Dataview inline field
使用Dataview inline field又想要使用Bases,可考慮使用 dataview-properties外掛,此外掛將inline fields同步到YAML區
還沒使用過,無法評斷。
💡 解說文章(繁體中文): https://jdev.tw/blog/8832/
💡 Explanation article(English):
💡 解説記事(日本語):
💡 相關鏈接
✅ Dataview Converter: Bases Toolbox
✅ Bases Syntax: Bases syntax - Obsidian Help
✅ obsidian-dataview-properties plugin: https://github.com/Mara-Li/obsidian-dataview-properties
##