FastComments.com

在你的 Jekyll 網站新增留言


這是 FastComments 的官方 Jekyll 函式庫。

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

儲存庫

在 GitHub 上查看


線上展示 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 會覆蓋由頁面派生的值,而頁面派生的值又會覆蓋任何全域預設。

屬性語法

屬性為 key=value 的配對,使用 snake_case

{% raw %}{% fastcomments url_id="my-stable-id" readonly=true count=20 %}{% endraw %}
  • Quoted values ("..." or '...') are literal strings.
  • Unquoted true/false become booleans, and numbers become numbers.
  • Unquoted anything else is resolved as a Liquid variable from the page context, e.g. url_id=page.slug. (Liquid does not expand {% raw %}\{{ ... }}{% endraw %} inside a tag's attributes, so use the bare page.slug form rather than "{% raw %}\{{ page.slug }}{% endraw %}".)

Snake_case attribute and config keys are mapped automatically to the camelCase keys FastComments expects (tenant_idtenantId, url_idurlId, page_titlepageTitle, has_dark_backgroundhasDarkBackground, and so on). Any other option from the widget configuration passes straight through the same way.

由頁面派生的值

對於頁面作用域的 widgets (fastcomments, fastcomments_comment_count, fastcomments_live_chat, fastcomments_collab_chat, fastcomments_image_chat),這些值會自動從當前頁面填入,除非你自行設定:

  • url_idpage.url (a stable identifier independent of the visiting domain)
  • urlsite.url + page.url (only when url is set in _config.yml)
  • page_titlepage.title

Site-wide widgets (recent comments/discussions, top pages, reviews summary, user activity feed, bulk count) are not tied to a page and do not derive these.

歐盟資料駐留

歐盟客戶請新增 region: eu,可以全域設定:

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

或是每個標籤設定: {% raw %}{% fastcomments region="eu" %}{% endraw %}。小工具將會從歐盟的 CDN 載入。



維護狀態 Internal Link

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

需要幫助?

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

貢獻

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