FastComments.com

FastCommentsは、特定のページや投稿のコメント数を表示できる軽量で独立したコメント数ウィジェットを提供します。これらのウィジェットはメインのコメントウィジェットとは別で、フルのコメントインターフェースを表示せずにコメント数を見せたい場所で使用するよう設計されています。

There are two types of comment count widgets available:

  1. Comment Count Widget - 単一ページのコメント数を表示するためのウィジェット
  2. Bulk Comment Count Widget - 同一ページ上で複数のページにわたるコメント数を効率的に表示するためのウィジェット

This article covers the VanillaJS widgets. Our React/Angular/etc libraries also have their own widgets。


コメント数ウィジェットのインストール Internal Link

コメントカウントウィジェットは、単一ページのコメント数を表示するために設計されています。軽量で、設定すればリアルタイム更新を提供します。

基本インストール

Comment Count Widget Installation
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/widget-comment-count.min.js"></script>
3<div id="comment-count"></div>
4<script>
5 window.FastCommentsCommentCount(document.getElementById('comment-count'), {
6 tenantId: 'demo'
7 });
8</script>
9

設定オプション

FastCommentsCommentCount関数は以下の設定オプションを受け入れます:

  • tenantId(必須):FastCommentsのテナントID
  • urlId(オプション):ページ識別子。指定しない場合はwindow.location.hrefがデフォルト
  • numberOnly(オプション):trueの場合、テキストなしで数字のみを表示。デフォルトはfalse
  • isLive(オプション):trueの場合、カウントは自動的に更新されます。デフォルトはfalse

高度な例

カスタムURL ID

Comment Count with Custom URL ID
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/widget-comment-count.min.js"></script>
3<div id="comment-count-custom"></div>
4<script>
5 window.FastCommentsCommentCount(document.getElementById('comment-count-custom'), {
6 tenantId: 'demo',
7 urlId: 'my-custom-page-id'
8 });
9</script>
10

数字のみの表示

Comment Count Number Only
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/widget-comment-count.min.js"></script>
3<div id="comment-count-number"></div>
4<script>
5 window.FastCommentsCommentCount(document.getElementById('comment-count-number'), {
6 tenantId: 'demo',
7 numberOnly: true
8 });
9</script>
10

ライブ更新

Live Comment Count Updates
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/widget-comment-count.min.js"></script>
3<div id="comment-count-live"></div>
4<script>
5 window.FastCommentsCommentCount(document.getElementById('comment-count-live'), {
6 tenantId: 'demo',
7 isLive: true
8 });
9</script>
10

ウィジェットメソッド

ウィジェットは以下のメソッドを持つオブジェクトを返します:

  • destroy():ウィジェットを削除し、すべてのタイマーをクリーンアップ
  • update(config):新しい設定でウィジェットを更新

使用例

Widget Methods Example
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/widget-comment-count.min.js"></script>
3<div id="comment-count-methods"></div>
4<script>
5 const widget = window.FastCommentsCommentCount(document.getElementById('comment-count-methods'), {
6 tenantId: 'demo'
7 });
8
9 // Update the widget to show a different page's count
10 setTimeout(() => {
11 widget.update({
12 tenantId: 'demo',
13 urlId: 'different-page-id'
14 });
15 }, 5000);
16
17 // Destroy the widget after 10 seconds
18 setTimeout(() => {
19 widget.destroy();
20 }, 10000);
21</script>
22

スタイリング

ウィジェットはコメント数を含むプレーンHTMLをレンダリングし、最小限のスタイリングで提供されます。CSSで外観をカスタマイズできます:

Custom Styling
Copy CopyRun External Link
1
2<style>
3 .comment-count-styled {
4 background: #f0f0f0;
5 padding: 5px 10px;
6 border-radius: 15px;
7 font-size: 14px;
8 color: #666;
9 display: inline-block;
10 }
11</style>
12<script src="https://cdn.fastcomments.com/js/widget-comment-count.min.js"></script>
13<div id="comment-count-styled" class="comment-count-styled"></div>
14<script>
15 window.FastCommentsCommentCount(document.getElementById('comment-count-styled'), {
16 tenantId: 'demo'
17 });
18</script>
19

コメント数ウィジェットの一括インストール Internal Link

バルクコメントカウントウィジェットは、同じページで複数のページのコメント数を効率的に表示するために設計されています。各コメント数に対して個別のAPI呼び出しを行う代わりに、このウィジェットはリクエストをバッチ処理して最適なパフォーマンスを実現します。

基本インストール

Bulk Comment Count Widget Installation
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/embed-widget-comment-count-bulk.min.js"></script>
3
4<!-- Multiple elements with comment counts -->
5<div class="fast-comments-count" data-fast-comments-url-id="page-1"></div>
6<div class="fast-comments-count" data-fast-comments-url-id="page-2"></div>
7<div class="fast-comments-count" data-fast-comments-url-id="page-3"></div>
8
9<script>
10 window.FastCommentsBulkCountConfig = {
11 tenantId: 'demo'
12 };
13</script>
14

動作の仕組み

バルクウィジェットは以下のように動作します:

  1. fast-comments-countクラスを持つ要素をページでスキャン
  2. 各要素からdata-fast-comments-url-id属性を読み取り
  3. 複数のコメント数を効率的に取得するためにAPIリクエストをバッチ処理
  4. 各要素を適切なコメント数で更新

設定オプション

FastCommentsCommentCountBulk関数は以下の設定オプションを受け入れます:

  • tenantId(必須):FastCommentsのテナントID
  • apiHost(オプション):セルフホストインスタンスを使用している場合のカスタムAPIホスト

実世界の例

ブログ投稿リストでバルクウィジェットを使用する方法を示す実用的な例:

Blog Post Listing with Comment Counts
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/embed-widget-comment-count-bulk.min.js"></script>
3
4<style>
5 .blog-post {
6 border: 1px solid #ddd;
7 margin: 10px 0;
8 padding: 15px;
9 border-radius: 5px;
10 }
11 .post-meta {
12 color: #666;
13 font-size: 14px;
14 margin-top: 10px;
15 }
16 .comment-count {
17 background: #e7f3ff;
18 padding: 2px 8px;
19 border-radius: 12px;
20 font-size: 12px;
21 display: inline-block;
22 }
23</style>
24
25<div class="blog-post">
26 <h3>How to Install FastComments</h3>
27 <p>Learn how to add FastComments to your website in just a few minutes...</p>
28 <div class="post-meta">
29 Published: March 15, 2024 |
30 <span class="fast-comments-count comment-count" data-fast-comments-url-id="how-to-install-fastcomments"></span>
31 </div>
32</div>
33
34<div class="blog-post">
35 <h3>Advanced FastComments Configuration</h3>
36 <p>Dive deep into the advanced configuration options for FastComments...</p>
37 <div class="post-meta">
38 Published: March 10, 2024 |
39 <span class="fast-comments-count comment-count" data-fast-comments-url-id="advanced-fastcomments-config"></span>
40 </div>
41</div>
42
43<div class="blog-post">
44 <h3>FastComments vs Other Solutions</h3>
45 <p>See how FastComments compares to other commenting solutions...</p>
46 <div class="post-meta">
47 Published: March 5, 2024 |
48 <span class="fast-comments-count comment-count" data-fast-comments-url-id="fastcomments-comparison"></span>
49 </div>
50</div>
51
52<script>
53 window.FastCommentsBulkCountConfig = {
54 tenantId: 'demo'
55 };
56</script>
57

パフォーマンスに関する考慮事項

バルクウィジェットは以下の方法でパフォーマンスを自動的に最適化します:

  • リクエストのバッチ処理:複数のコメント数が単一のAPI呼び出しで取得される
  • リクエストサイズ制限:URLリストが大きくなりすぎると(1,000文字以上)、リクエストは自動的に分割される
  • 重複排除:同じdata-fast-comments-url-idを持つ複数の要素は同じカウントを共有

同じURL IDを持つ複数の要素

同じdata-fast-comments-url-idを持つ複数の要素をページに配置できます。それらはすべて同じカウントで更新されます:

Multiple Elements Same URL ID
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/embed-widget-comment-count-bulk.min.js"></script>
3
4<style>
5 .count-example {
6 margin: 10px 0;
7 padding: 10px;
8 background: #f9f9f9;
9 border-radius: 5px;
10 }
11</style>
12
13<div class="count-example">
14 Header Count: <span class="fast-comments-count" data-fast-comments-url-id="shared-article"></span>
15</div>
16
17<div class="count-example">
18 Sidebar Count: <span class="fast-comments-count" data-fast-comments-url-id="shared-article"></span>
19</div>
20
21<div class="count-example">
22 Footer Count: <span class="fast-comments-count" data-fast-comments-url-id="shared-article"></span>
23</div>
24
25<script>
26 window.FastCommentsBulkCountConfig = {
27 tenantId: 'demo'
28 };
29</script>
30

ローカライゼーション

バルクウィジェットはFastCommentsの言語設定に基づいてコメント数を自動的にフォーマットします。以下に適切なテキストを提供します:

  • コメントなし
  • 1件のコメント
  • 複数のコメント

バルクウィジェットとシングルウィジェットの使い分け

バルクウィジェットを使用する場合:

  • 同じページに複数のコメント数がある
  • コメント数付きの投稿/記事リストを表示している
  • パフォーマンスが重要(API呼び出しを削減)

シングルウィジェットを使用する場合:

  • ページに1つのコメント数だけが必要
  • ライブ更新が必要(シングルウィジェットはリアルタイム更新をサポート)
  • 個々のウィジェットの動作をより細かく制御したい

FastComments のコメントカウントウィジェットは、サイト全体でコメント数を表示するためのシンプルで効率的な方法を提供します。

このドキュメントがお役に立てば幸いです。