FastComments.com

為您的 Jekyll 網站添加評論

這是 FastComments 的官方 Jekyll 函式庫。

在您的 Jekyll 網站嵌入即時評論、聊天和審閱小工具。

儲存庫

在 GitHub 上查看

AI 程式編寫代理 Internal Link

skills.sh

為您的程式編寫代理提供 FastComments 所需的上下文——小工具、設定、Secure SSO、REST API 與 SDK:

npx skills add fastcomments/skills

可與 Claude Code、Codex、Cursor、Copilot、Gemini 以及所有其他由 skills CLI 支援的代理一起使用。

即時展示 Internal Link

若要在本機查看針對公開 demo 租戶運行的所有標籤,請複製儲存庫並執行:

cd example
bundle install
bundle exec jekyll serve

每個 widget 在 example/ 底下都有自己的頁面,您可以直接將其複製到自己的 Jekyll 網站中。

安裝 Internal Link

Gem

將 gem 新增到您網站的 Gemfile 中的 :jekyll_plugins 群組:

group :jekyll_plugins do
  gem "fastcomments-jekyll"
end

然後:

bundle install

(相容於 Jekyll 3.7+ 與 4.x。)

標籤 Internal Link

TagDescription
fastcomments即時留言功能,支援回覆、投票、審核與即時更新
fastcomments_comment_count當前頁面的留言數量
fastcomments_comment_count_bulk清單/索引頁面上多個頁面的留言數量
fastcomments_live_chat即時串流聊天小工具
fastcomments_collab_chat協作式內嵌留言(文字註解)
fastcomments_image_chat圖像註解留言
fastcomments_recent_comments全站最近留言
fastcomments_recent_discussions最近活躍的討論串
fastcomments_reviews_summary星級評分評論摘要
fastcomments_top_pages討論最多的頁面
fastcomments_user_activity_feed每位使用者的活動動態

範例

{% raw %}{# 留言數量。該小工具會自行呈現標籤,例如「0 則留言」 #}
{% fastcomments_comment_count %}

{# 即時聊天 #}
{% fastcomments_live_chat %}

{# 協作聊天。指定一個帶 CSS 選擇器的內容元素 #}
<article id="post-body">
  <p>Highlight me to leave a comment.</p>
</article>
{% fastcomments_collab_chat target="#post-body" %}

{# 圖像聊天。指定一個帶 CSS 選擇器的圖像元素 #}
<img id="hero" src="/hero.jpg" alt="Hero image">
{% fastcomments_image_chat target="#hero" %}

{# 評論摘要 #}
{% fastcomments_reviews_summary %}

{# 使用者活動動態。需要 user_id #}
{% fastcomments_user_activity_feed user_id="demo:demo-user" %}

{# 部落格索引的批量留言計數 #}
{% for post in site.posts %}
  <a href="\{{ post.url }}">\{{ post.title }}</a>
  <span class="fast-comments-count" data-fast-comments-url-id="\{{ post.url }}"></span>
{% endfor %}
{% fastcomments_comment_count_bulk %}{% endraw %}

設定 Internal Link

設定來自三個地方,後面的來源會覆蓋前面的:

  1. _config.yml 中 fastcomments: 鍵下的全域預設值。
  2. 頁面上下文,針對頁面範圍的小工具自動推導(見下方)。
  3. 寫在標籤本身的標籤屬性。

因此標籤上的 url_id 會覆蓋頁面推導的值,而後者又會覆蓋任何全域預設值。

屬性語法

屬性是以 snake_case 表示的 key=value 配對:

{% raw %}{% fastcomments url_id="my-stable-id" readonly=true count=20 %}{% endraw %}
  • 加引號的值("..." 或 '...')為字面字串。
  • 未加引號的 true/false 會轉為布林值,數字則轉為數字。
  • 未加引號的其他任何內容會從頁面上下文中解析為 Liquid 變數,例如 url_id=page.slug。(Liquid 不會在標籤的屬性中展開 {% raw %}\{{ ... }}{% endraw %}, 因此請使用裸的 page.slug 形式,而不是 "{% raw %}\{{ page.slug }}{% endraw %}"。)

snake_case 的屬性與設定鍵會自動對應到 FastComments 預期的 camelCase 鍵 (tenant_id → tenantId、url_id → urlId、page_title → pageTitle、 has_dark_background → hasDarkBackground,依此類推)。 小工具設定中的任何其他選項 也會以相同方式直接傳遞。

頁面推導的值

對於頁面範圍的小工具(fastcomments、fastcomments_comment_count、fastcomments_live_chat、 fastcomments_collab_chat、fastcomments_image_chat),除非您自行設定,否則以下值會從 目前頁面自動填入:

  • url_id ← page.url(與造訪網域無關的穩定識別碼)
  • url ← site.url + page.url(僅當 _config.yml 中設定了 url 時)
  • page_title ← page.title

全站小工具(最新留言/討論、熱門頁面、評論摘要、使用者活動動態、 批次計數)不綁定於特定頁面,因此不會推導這些值。

EU 資料駐留

EU 客戶可新增 region: eu,可以全域設定:

fastcomments:
  tenant_id: your-tenant-id
  region: eu

或在每個標籤上設定:{% raw %}{% fastcomments region="eu" %}{% endraw %}。小工具屆時會從 EU CDN 載入。

維護狀態 Internal Link

這些元件是我們核心 VanillaJS 元件的封裝。我們可以自動更新那些元件(修復錯誤、加入功能),而不需要發佈這個程式庫,所以即便這個程式庫可能一段時間不會發佈,也不代表 FastComments 沒有在積極開發中!歡迎查看 我們的部落格 以獲取更新。重大破壞性 API 變更或功能不會在未提升此程式庫版本的情況下,併入到底層核心程式庫。

需要幫助?

如果您在使用 Jekyll 函式庫時遇到任何問題或有任何疑問,請:

貢獻

歡迎貢獻!請造訪 GitHub 倉庫 以取得貢獻指南。