DisqusUtterances 評論小部件都是開箱即用的。本文將展示如何配置它們,甚至自定義你自己的評論小部件。

Disqus

Disqus 評論小部件由 Hugo 支持。

1disqusShortname = "yourdiscussshortname"

請注意:disqusShortname 是站點配置,而非參數。將其放在 params 是行不通的。

Utterances

Utterances 是一個基於 GitHub issue 的輕量級評論小部件。

1[utterances]
2  repo = "user/repo"
3  #issueTerm = "pathname" # pathname, url, title, og:title.
4  #label = "comment" # Optional.
5  #theme = ""

不同於 Disqus,Utterances 是一個參數。請將其放置在 params

參數

名稱類型默認值描述
utterances.repoString-GitHub 倉庫。
utterances.issueTermStringpathname文章和 issue 之間的映射: pathname
utterances.labelString-此標籤會分配給 Utterances 創建的 issue。
utterances.themeString-如果未設置任何主題,亮色和暗色模式會分別使用 github-lightgithub-dark。 可選值: github-light, github-dark, preferred-color-scheme, github-dark-orange, icy-dark, dark-bluephoton-dark

故障排查

  • 確保倉庫是公開的,否則讀者無法查看評論。
  • 確保倉庫已經安裝了 utterances app ,否則用戶無法發表評論。
  • 如果你的倉庫是尅隆的,請在設定中確保已經啟用了 issues 功能。

自定義評論小部件

我們不打算支持所有的評論小部件,但別擔心,你完全可以自定義評論小部件。

在創建自己的評論小部件之前,需要禁用其他評論小部件。

1mkdir -p layouts/partials/post/comments
2echo "MY COMMENTS WIDGET" > layouts/partials/post/comments/custom.html

期間,你很可能需要引入協力廠商資源,不過這可以通過 自定義資源鉤子 輕鬆解决。