跳轉至

程式庫連結(Repository)

如果文件和原始碼有關,Zensical 可以在網站上顯示專案程式庫的資訊,包含最新版本、星星數與 fork 數,也可以提供「檢視原始碼」與「編輯此頁」按鈕。

程式庫網址

設定 repo_url 之後,程式庫連結會顯示在大螢幕的搜尋列旁邊:

[project]
repo_url = "https://github.com/zensical/zensical"

若是託管在 GitHub 或 GitLab 的公開程式庫,還會自動取得並顯示最新發行版本、星星數與 fork 數。

要建立 Release,不是只有 tag

GitHub 的 API 只能取得「最新 release」而不是最新 tag,所以請為想顯示的版本建立正式的 release(不是 pre-release)。GitLab 也一樣。

程式庫名稱與圖示

Zensical 會從網址推測程式庫的供應商(例如 GitHub)作為名稱。想自訂就用 repo_name

[project]
repo_name = "zensical/zensical"

預設圖示是通用的 git 圖示,可以換成任何內建圖示:

[project.theme.icon]
repo = "fontawesome/brands/github"

常用的選擇:fontawesome/brands/gitgit-altgithubgithub-altgitlabgitkrakenbitbucket

內容動作按鈕

Zensical 可以在每一頁顯示按鈕,讓讀者一鍵跳到程式庫中該頁的原始碼,或直接在 Git 託管網站上編輯:

[project.theme]
features = [
  "content.action.edit",   # 編輯此頁
  "content.action.view",   # 檢視此頁原始碼
]

如果 repo_url 指向 GitHub,Zensical 會自動推導出對應網址,只要開啟這兩個旗標即可。

使用 edit_uri

如果使用自訂的分支名稱或 docs_dir,就需要設定 edit_uri 來覆寫預設路徑。網址是由 repo_urledit_uri 與該 Markdown 檔在 docs_dir 內的路徑串接而成:

[project]
edit_uri = "edit/main/docs/"

文件放在另一個程式庫

如果專案與文件放在不同的程式庫,edit_uri 可以直接寫成絕對網址,就不再依賴 repo_url。這時 repo_url 指向專案程式庫,edit_uri 指向文件程式庫。

更換按鈕圖示

[project.theme.icon]
edit = "material/pencil"
view = "material/eye"

總結

設定 用途
repo_url 顯示程式庫連結、版本與星星數
repo_name 自訂顯示名稱
theme.icon.repo 自訂程式庫圖示
content.action.edit / .view 「編輯此頁」/「檢視原始碼」按鈕
edit_uri 自訂編輯網址的路徑

參考資料