部署到 Cloudflare Workers(Quartz)
跟你的 hbs-vault 同套架構:Quartz on Cloudflare Workers,加一個 Dataview 預處理腳本。
雙模式架構
| 本地 Obsidian | 部署版 | |
|---|---|---|
| Dataview | 動態 render | 預處理腳本靜態化(build 階段執行查詢、結果寫進 markdown) |
| Templater | 完整功能 | 不需要(部署版不會建立新檔) |
| Wikilinks | 完整功能 | Quartz 自動處理 |
| Graph view | 完整功能 | Quartz 內建 |
一鍵 build
cd /c/Users/alber/Desktop/AI_Playground/mental-models-vault
python _scripts/prep_for_quartz.py輸出在 _build/quartz-content/,這是 Quartz 直接 consume 的乾淨 markdown。
部署步驟(首次)
1. 設定 Quartz 專案
如果還沒有對應的 Quartz repo:
cd /c/Users/alber/Desktop/AI_Playground
git clone https://github.com/jackyzha0/quartz.git mental-models-quartz
cd mental-models-quartz
npm install2. 把 build 輸出指向 Quartz content
兩個選擇:
Option A|symlink(推薦,自動同步)
cd /c/Users/alber/Desktop/AI_Playground/mental-models-quartz
rm -rf content
ln -s ../mental-models-vault/_build/quartz-content contentWindows symlink 需要管理員權限或開啟開發者模式。如果不能用 symlink,改 Option B。
Option B|手動複製(每次 build 後執行)
cd /c/Users/alber/Desktop/AI_Playground
rm -rf mental-models-quartz/content/*
cp -r mental-models-vault/_build/quartz-content/* mental-models-quartz/content/3. 設定 Quartz config
編輯 mental-models-quartz/quartz.config.ts:
configuration: {
pageTitle: "Mental Models Vault|決策工具箱",
enableSPA: true,
enablePopovers: true,
analytics: { provider: "plausible" }, // 或關掉
locale: "zh-TW",
baseUrl: "mental-models.albertckchien.workers.dev",
ignorePatterns: ["private", "templates", ".obsidian", "_build"],
defaultDateType: "created",
theme: {
fontOrigin: "googleFonts",
cdnCaching: true,
typography: {
header: "Noto Serif TC",
body: "Noto Serif TC",
code: "JetBrains Mono",
},
colors: {
// 你的色票
},
},
},4. 本地預覽
cd mental-models-quartz
npx quartz build --serve
# 開 http://localhost:80805. 部署到 CF Workers
跟 hbs-vault 同套:
# 1. build static site
npx quartz build
# 2. 用 wrangler 部署
npx wrangler deploywrangler.toml 範例:
name = "mental-models"
main = "src/worker.ts"
compatibility_date = "2026-01-01"
[site]
bucket = "./public"日常更新流程
# 1. 在 mental-models-vault 內編輯(本地 Obsidian)
# 2. build
cd /c/Users/alber/Desktop/AI_Playground/mental-models-vault
python _scripts/prep_for_quartz.py
# 3. 如果用 Option B,把 content 同步到 quartz
cp -r _build/quartz-content/* ../mental-models-quartz/content/
# 4. 部署
cd ../mental-models-quartz
npx quartz build
npx wrangler deploy預期 URL
https://mental-models.albertckchien.workers.dev/
(或你自訂的 CF Worker 子網域)
Dataview 靜態化|支援範圍
prep_for_quartz.py 在 build 時把 Obsidian Dataview 查詢轉成靜態 markdown。支援的子集:
TABLE [col1 AS "alias", col2, ...]LISTFROM "folder-path"WHERE field = "value"WHERE contains(field, "value")WHERE field(truthy 檢查)SORT field ASC|DESC
不支援(會原樣保留並警告,需要時可擴充腳本):
DataviewJS(JavaScript 查詢)FLATTEN/GROUP BY- 跨檔案 inline field
- 複雜的
expr.subfield存取
.gitignore 建議
vault 內的 .gitignore:
_build/
.obsidian/workspace.json
.trash/
Quartz repo 內的 .gitignore:
content/ # 因為 content 是 build artifact / symlink
public/
node_modules/
.quartz-cache/
排錯
問題:build 完看不到某些 dataview 結果 原因:可能 frontmatter YAML 解析失敗(value 含冒號沒引號等) 解法:檢查 frontmatter 約定 的 3 條鐵律
問題:CJK 路徑亂碼 原因:Windows console 編碼(cp950 vs UTF-8) 解法:腳本內部處理用 UTF-8,console 顯示亂碼不影響輸出檔內容