fastcomments-jekyll 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bbac3e1304d9a1a11836ab18c647a3af98b76c462dac4facd8455e0a4429a574
4
+ data.tar.gz: fc1b60e6e89f8a356032296b1787ef6c18384ee9d461a71b1727f1d4295d682b
5
+ SHA512:
6
+ metadata.gz: f512271ee861ec296f97ab0004b1e45962fcc36f426d031d7c9ee5c7fdf703a41f4234d635e7557af941a5a1be08ac7f338d51c8e8273c3d5a3a6292670b03e3
7
+ data.tar.gz: 6e007a7a756c966587894535bc553c0dcae674fb34f3d17f726127593aced746acce011e116a9a63e5f671c788a2ea25184f13430227520dfb351cbbccd727cd
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ Initial release. Liquid tags for embedding FastComments widgets into Jekyll sites:
6
+
7
+ - `fastcomments` - live commenting widget
8
+ - `fastcomments_comment_count` - comment count for a page
9
+ - `fastcomments_comment_count_bulk` - comment counts for many pages on one list/index page
10
+ - `fastcomments_live_chat` - live chat widget
11
+ - `fastcomments_collab_chat` - collaborative inline commenting (text annotations)
12
+ - `fastcomments_image_chat` - image annotation comments
13
+ - `fastcomments_recent_comments` - recent comments across the site
14
+ - `fastcomments_recent_discussions` - recently active discussion threads
15
+ - `fastcomments_reviews_summary` - star-rating reviews summary
16
+ - `fastcomments_top_pages` - most-discussed pages
17
+ - `fastcomments_user_activity_feed` - per-user activity feed
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FastComments
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # fastcomments-jekyll
2
+
3
+ A fast, full-featured live commenting widget for [Jekyll](https://jekyllrb.com), powered by [FastComments](https://fastcomments.com).
4
+
5
+ Adds Liquid tags like `{% raw %}{% fastcomments %}{% endraw %}` that you drop straight into your templates and posts.
6
+
7
+ ## Live Demo
8
+
9
+ Try every widget live at <https://fastcomments.com/commenting-system-for-jekyll>.
10
+
11
+ ## Live Showcase
12
+
13
+ To see every tag running locally against the public `demo` tenant, clone the repo and run:
14
+
15
+ ```bash
16
+ cd example
17
+ bundle install
18
+ bundle exec jekyll serve
19
+ ```
20
+
21
+ Each widget has its own page under `example/` that you can copy straight into your own Jekyll site.
22
+
23
+ ## Install
24
+
25
+ [![Gem](https://img.shields.io/gem/v/fastcomments-jekyll?logo=rubygems&label=gem&color=e9573f)](https://rubygems.org/gems/fastcomments-jekyll)
26
+
27
+ Add the gem to the `:jekyll_plugins` group in your site's `Gemfile`:
28
+
29
+ ```ruby
30
+ group :jekyll_plugins do
31
+ gem "fastcomments-jekyll"
32
+ end
33
+ ```
34
+
35
+ Then:
36
+
37
+ ```bash
38
+ bundle install
39
+ ```
40
+
41
+ (Compatible with Jekyll 3.7+ and 4.x.)
42
+
43
+ ## Quick Start
44
+
45
+ Set your tenant id once in `_config.yml`:
46
+
47
+ ```yaml
48
+ fastcomments:
49
+ tenant_id: demo
50
+ ```
51
+
52
+ Then add a tag wherever you want the widget, in a layout, a post, or a page:
53
+
54
+ ```liquid
55
+ {% raw %}{% fastcomments %}{% endraw %}
56
+ ```
57
+
58
+ That's it. Replace `demo` with your FastComments tenant id (find it under
59
+ [Settings > API/SSO](https://fastcomments.com/auth/my-account/api)).
60
+
61
+ ## Tags
62
+
63
+ | Tag | Description |
64
+ | --- | --- |
65
+ | `fastcomments` | Live commenting with replies, voting, moderation, and realtime updates |
66
+ | `fastcomments_comment_count` | Comment count for the current page |
67
+ | `fastcomments_comment_count_bulk` | Comment counts for many pages on one list/index page |
68
+ | `fastcomments_live_chat` | Realtime streaming chat widget |
69
+ | `fastcomments_collab_chat` | Collaborative inline commenting (text annotations) |
70
+ | `fastcomments_image_chat` | Image annotation comments |
71
+ | `fastcomments_recent_comments` | Recent comments across the site |
72
+ | `fastcomments_recent_discussions` | Recently active discussion threads |
73
+ | `fastcomments_reviews_summary` | Star-rating reviews summary |
74
+ | `fastcomments_top_pages` | Most-discussed pages |
75
+ | `fastcomments_user_activity_feed` | Per-user activity feed |
76
+
77
+ ### Examples
78
+
79
+ ```liquid
80
+ {% raw %}{# Comment count. The widget renders its own label, e.g. "0 comments" #}
81
+ {% fastcomments_comment_count %}
82
+
83
+ {# Live chat #}
84
+ {% fastcomments_live_chat %}
85
+
86
+ {# Collab chat. Point it at a content element with a CSS selector #}
87
+ <article id="post-body">
88
+ <p>Highlight me to leave a comment.</p>
89
+ </article>
90
+ {% fastcomments_collab_chat target="#post-body" %}
91
+
92
+ {# Image chat. Point it at an image element with a CSS selector #}
93
+ <img id="hero" src="/hero.jpg" alt="Hero image">
94
+ {% fastcomments_image_chat target="#hero" %}
95
+
96
+ {# Reviews summary #}
97
+ {% fastcomments_reviews_summary %}
98
+
99
+ {# User activity feed. Requires a user id #}
100
+ {% fastcomments_user_activity_feed user_id="demo:demo-user" %}
101
+
102
+ {# Bulk comment counts for a blog index #}
103
+ {% for post in site.posts %}
104
+ <a href="{{ post.url }}">{{ post.title }}</a>
105
+ <span class="fast-comments-count" data-fast-comments-url-id="{{ post.url }}"></span>
106
+ {% endfor %}
107
+ {% fastcomments_comment_count_bulk %}{% endraw %}
108
+ ```
109
+
110
+ ## Configuration
111
+
112
+ Config comes from three places. Later sources win:
113
+
114
+ 1. **Global defaults** in `_config.yml` under the `fastcomments:` key.
115
+ 2. **Page context**, derived automatically for page-scoped widgets (see below).
116
+ 3. **Tag attributes** written on the tag itself.
117
+
118
+ So a `url_id` on the tag overrides the page-derived value, which overrides any global default.
119
+
120
+ ### Attribute syntax
121
+
122
+ Attributes are `key=value` pairs in `snake_case`:
123
+
124
+ ```liquid
125
+ {% raw %}{% fastcomments url_id="my-stable-id" readonly=true count=20 %}{% endraw %}
126
+ ```
127
+
128
+ - **Quoted** values (`"..."` or `'...'`) are literal strings.
129
+ - **Unquoted** `true`/`false` become booleans, and numbers become numbers.
130
+ - **Unquoted** anything else is resolved as a Liquid variable from the page context, e.g.
131
+ `url_id=page.slug`. (Liquid does not expand `{% raw %}{{ ... }}{% endraw %}` inside a tag's
132
+ attributes, so use the bare `page.slug` form rather than `"{% raw %}{{ page.slug }}{% endraw %}"`.)
133
+
134
+ Snake_case attribute and config keys are mapped automatically to the camelCase keys FastComments
135
+ expects (`tenant_id` → `tenantId`, `url_id` → `urlId`, `page_title` → `pageTitle`,
136
+ `has_dark_background` → `hasDarkBackground`, and so on). Any other option from the
137
+ [widget configuration](https://docs.fastcomments.com/guide-customizations-and-configuration.html)
138
+ passes straight through the same way.
139
+
140
+ ### Page-derived values
141
+
142
+ For the page-scoped widgets (`fastcomments`, `fastcomments_comment_count`, `fastcomments_live_chat`,
143
+ `fastcomments_collab_chat`, `fastcomments_image_chat`) these are filled in automatically from the
144
+ current page unless you set them yourself:
145
+
146
+ - `url_id` ← `page.url` (a stable identifier independent of the visiting domain)
147
+ - `url` ← `site.url` + `page.url` (only when `url` is set in `_config.yml`)
148
+ - `page_title` ← `page.title`
149
+
150
+ Site-wide widgets (recent comments/discussions, top pages, reviews summary, user activity feed,
151
+ bulk count) are not tied to a page and do not derive these.
152
+
153
+ ### EU data residency
154
+
155
+ EU customers add `region: eu`, either globally:
156
+
157
+ ```yaml
158
+ fastcomments:
159
+ tenant_id: your-tenant-id
160
+ region: eu
161
+ ```
162
+
163
+ or per tag: `{% raw %}{% fastcomments region="eu" %}{% endraw %}`. Widgets then load from the EU CDN.
164
+
165
+ ## Links
166
+
167
+ - [FastComments Documentation](https://docs.fastcomments.com)
168
+ - [Customization & Configuration](https://docs.fastcomments.com/guide-customizations-and-configuration.html)
169
+ - [Jekyll Documentation](https://jekyllrb.com/docs/)
170
+
171
+ ## License
172
+
173
+ MIT
174
+
175
+ ## Maintenance Status
176
+
177
+ These components are wrappers around our core VanillaJS components. We can automatically update those components (fix bugs, add features) without publishing this library, so while it may not be published for a while that does not mean FastComments is not under active development! Feel free to check [our blog](https://blog.fastcomments.com/) for updates. Breaking API changes or features will never be shipped to the underlying core library without a version bump in this library.
@@ -0,0 +1,48 @@
1
+ module FastComments
2
+ module Jekyll
3
+ # Parses a Liquid tag's markup ("k=v k='s' k=page.x") into a snake-keyed Hash.
4
+ module AttributeParser
5
+ module_function
6
+
7
+ TOKEN_RE = /([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/.freeze
8
+
9
+ def parse(markup, context)
10
+ result = {}
11
+ return result if markup.nil?
12
+
13
+ markup.scan(TOKEN_RE) do |key, double_quoted, single_quoted, bare|
14
+ if !double_quoted.nil?
15
+ result[key] = double_quoted
16
+ elsif !single_quoted.nil?
17
+ result[key] = single_quoted
18
+ else
19
+ value = coerce(bare, context)
20
+ result[key] = value unless value.nil?
21
+ end
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ # Unquoted values coerce to Integer/Float/Boolean/nil, else resolve as a
28
+ # Liquid context variable (e.g. page.slug). Unresolved variables become nil.
29
+ def coerce(token, context)
30
+ case token
31
+ when /\A-?\d+\z/ then Integer(token, 10)
32
+ when /\A-?\d*\.\d+\z/ then Float(token)
33
+ when "true" then true
34
+ when "false" then false
35
+ when "nil", "null" then nil
36
+ else
37
+ return nil if context.nil?
38
+
39
+ begin
40
+ context[token]
41
+ rescue StandardError
42
+ nil
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,52 @@
1
+ require "liquid"
2
+
3
+ module FastComments
4
+ module Jekyll
5
+ # Shared Liquid::Tag lifecycle: parse markup -> resolve config -> render widget.
6
+ # Concrete tags declare a `self.spec` and inherit one of the renderer bases below.
7
+ class BaseTag < ::Liquid::Tag
8
+ def render(context)
9
+ attrs = AttributeParser.parse(@markup, context)
10
+ config = ConfigResolver.resolve(context, attrs, derive_page_context: self.class.page_scoped?)
11
+ render_widget(config)
12
+ end
13
+
14
+ def self.page_scoped?
15
+ spec[:page_scoped] == true
16
+ end
17
+
18
+ def render_widget(_config)
19
+ raise NotImplementedError, "#{self.class} must implement #render_widget"
20
+ end
21
+ end
22
+
23
+ class ContainerTag < BaseTag
24
+ def render_widget(config)
25
+ ContainerWidget.render(self.class.spec, config)
26
+ end
27
+ end
28
+
29
+ class SelectorTag < BaseTag
30
+ def render_widget(config)
31
+ SelectorWidget.render(self.class.spec, config)
32
+ end
33
+ end
34
+
35
+ # The user activity feed is keyed by a user id rather than a page.
36
+ class UserActivityTag < ContainerTag
37
+ def render_widget(config)
38
+ unless config["userId"].is_a?(String) && !config["userId"].empty?
39
+ raise ::Liquid::SyntaxError, "fastcomments_user_activity_feed tag requires a \"user_id\" option."
40
+ end
41
+
42
+ super
43
+ end
44
+ end
45
+
46
+ class BulkCountTag < BaseTag
47
+ def render_widget(config)
48
+ BulkCountWidget.render(self.class.spec, config)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,30 @@
1
+ module FastComments
2
+ module Jekyll
3
+ # Renders the bulk comment-count loader: sets the global config object, then
4
+ # lazy-loads the bulk script once. The script scans the page for elements with
5
+ # class "fast-comments-count" and a data-fast-comments-url-id attribute.
6
+ module BulkCountWidget
7
+ module_function
8
+
9
+ def render(spec, config)
10
+ clean = Util.sanitize_config(config)
11
+ region = clean["region"]
12
+ script_src = "#{Util.get_cdn_base(region)}#{spec[:script_path]}"
13
+
14
+ "<script>" \
15
+ "(function(){" \
16
+ "window.#{spec[:global_name]}=#{Util.json_for_script(clean)};" \
17
+ "var scriptSrc=#{Util.json_for_script(script_src)};" \
18
+ "var marker=#{Util.json_for_script(spec[:script_marker_attr])};" \
19
+ "if(!document.querySelector('script['+marker+']')){" \
20
+ "var s=document.createElement('script');" \
21
+ "s.src=scriptSrc;" \
22
+ "s.setAttribute(marker,'');" \
23
+ "document.head.appendChild(s);" \
24
+ "}" \
25
+ "})();" \
26
+ "</script>"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,62 @@
1
+ module FastComments
2
+ module Jekyll
3
+ # Merges widget config from three sources and camelizes the result.
4
+ # Precedence (later wins): global _config.yml defaults < page-derived < tag attributes.
5
+ module ConfigResolver
6
+ module_function
7
+
8
+ def resolve(context, attrs, derive_page_context: false)
9
+ merged = {}
10
+
11
+ global_config(context).each { |key, value| merged[key.to_s] = value }
12
+
13
+ if derive_page_context
14
+ derive(context).each { |key, value| merged[key] = value unless value.nil? }
15
+ end
16
+
17
+ attrs.each { |key, value| merged[key.to_s] = value }
18
+
19
+ KeyMapper.map_keys(Util.sanitize_config(merged))
20
+ end
21
+
22
+ def global_config(context)
23
+ site = site(context)
24
+ return {} unless site
25
+
26
+ config = site.config["fastcomments"]
27
+ config.is_a?(Hash) ? config : {}
28
+ end
29
+
30
+ def derive(context)
31
+ page = page(context)
32
+ # Real Jekyll exposes `page` as a Liquid::Drop (Jekyll::Drops::DocumentDrop),
33
+ # not a Hash; both answer page["url"]/page["title"], so guard on [] not Hash.
34
+ return {} unless page.respond_to?(:[])
35
+
36
+ derived = {}
37
+ derived["url_id"] = page["url"] if page["url"]
38
+
39
+ site = site(context)
40
+ site_url = site ? site.config["url"] : nil
41
+ derived["url"] = "#{site_url}#{page["url"]}" if site_url && !site_url.to_s.empty? && page["url"]
42
+
43
+ derived["page_title"] = page["title"] if page["title"]
44
+ derived
45
+ end
46
+
47
+ def site(context)
48
+ registers = context.registers
49
+ site = registers && registers[:site]
50
+ site if site.respond_to?(:config)
51
+ rescue StandardError
52
+ nil
53
+ end
54
+
55
+ def page(context)
56
+ context["page"]
57
+ rescue StandardError
58
+ nil
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,54 @@
1
+ module FastComments
2
+ module Jekyll
3
+ # Renders a container widget (a div/span placeholder + a self-contained loader
4
+ # script). Port of renderContainerWidget from fastcomments-11ty.
5
+ module ContainerWidget
6
+ module_function
7
+
8
+ def render(spec, config)
9
+ clean = Util.sanitize_config(config)
10
+ region = clean["region"]
11
+ container_id = Util.make_container_id(spec[:container_id_prefix])
12
+ script_src = "#{Util.get_cdn_base(region)}#{spec[:script_path]}"
13
+
14
+ global_name = spec[:global_name]
15
+ label = spec[:error_label] || global_name
16
+ slow_warn = "FastComments #{label} script did not load within 5s; continuing to retry every 1s."
17
+
18
+ init_body =
19
+ if spec[:use_callback]
20
+ failure = Util.json_for_script("FastComments #{label} Load Failure")
21
+ "if(window.#{global_name}){window.#{global_name}(el,config,function(error){" \
22
+ "if(error){console.error(#{failure},error);}});}else{schedule();}"
23
+ else
24
+ "if(window.#{global_name}){window.#{global_name}(el,config);}else{schedule();}"
25
+ end
26
+
27
+ tag = spec[:container_tag]
28
+
29
+ "<#{tag} id=\"#{Util.escape_attr(container_id)}\"></#{tag}>" \
30
+ "<script>" \
31
+ "(function(){" \
32
+ "var containerId=#{Util.json_for_script(container_id)};" \
33
+ "var config=#{Util.json_for_script(clean)};" \
34
+ "var scriptSrc=#{Util.json_for_script(script_src)};" \
35
+ "var marker=#{Util.json_for_script(spec[:script_marker_attr])};" \
36
+ "var startedAt=Date.now();" \
37
+ "var warned=false;" \
38
+ "function schedule(){var elapsed=Date.now()-startedAt;" \
39
+ "if(elapsed>=5000&&!warned){warned=true;console.warn(#{Util.json_for_script(slow_warn)});}" \
40
+ "setTimeout(init,elapsed<5000?50:1000);}" \
41
+ "function init(){var el=document.getElementById(containerId);#{init_body}}" \
42
+ "if(!document.querySelector('script['+marker+']')){" \
43
+ "var s=document.createElement('script');" \
44
+ "s.src=scriptSrc;" \
45
+ "s.setAttribute(marker,'');" \
46
+ "document.head.appendChild(s);" \
47
+ "}" \
48
+ "init();" \
49
+ "})();" \
50
+ "</script>"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ module FastComments
2
+ module Jekyll
3
+ # Maps snake_case tag/_config keys to the camelCase keys FastComments expects.
4
+ module KeyMapper
5
+ module_function
6
+
7
+ def to_camel(key)
8
+ str = key.to_s
9
+ return str unless str.include?("_")
10
+
11
+ parts = str.split("_")
12
+ head = parts.shift
13
+ head + parts.map { |part| part.empty? ? "" : part[0].upcase + part[1..] }.join
14
+ end
15
+
16
+ # Camelize top-level keys only; nested values (e.g. translations) pass through verbatim.
17
+ def map_keys(hash)
18
+ hash.each_with_object({}) { |(key, value), out| out[to_camel(key)] = value }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ module FastComments
2
+ module Jekyll
3
+ # Renders a selector widget that attaches to an existing element via a CSS
4
+ # selector (collab chat, image chat). Port of renderSelectorWidget.
5
+ module SelectorWidget
6
+ module_function
7
+
8
+ def render(spec, config)
9
+ clean = Util.sanitize_config(config)
10
+ target = clean["target"]
11
+
12
+ unless target.is_a?(String) && !target.empty?
13
+ raise Liquid::SyntaxError,
14
+ "#{spec[:shortcode_name]} tag requires a \"target\" option (CSS selector for the target element)."
15
+ end
16
+
17
+ clean = clean.reject { |key, _| key == "target" }
18
+ region = clean["region"]
19
+ script_src = "#{Util.get_cdn_base(region)}#{spec[:script_path]}"
20
+
21
+ global_name = spec[:global_name]
22
+ slow_warn = "FastComments #{spec[:shortcode_name]} script did not load within 5s; continuing to retry every 1s."
23
+
24
+ "<script>" \
25
+ "(function(){" \
26
+ "var target=#{Util.json_for_script(target)};" \
27
+ "var config=#{Util.json_for_script(clean)};" \
28
+ "var scriptSrc=#{Util.json_for_script(script_src)};" \
29
+ "var marker=#{Util.json_for_script(spec[:script_marker_attr])};" \
30
+ "var startedAt=Date.now();" \
31
+ "var warned=false;" \
32
+ "function schedule(){var elapsed=Date.now()-startedAt;" \
33
+ "if(elapsed>=5000&&!warned){warned=true;console.warn(#{Util.json_for_script(slow_warn)});}" \
34
+ "setTimeout(init,elapsed<5000?50:1000);}" \
35
+ "function init(){if(window.#{global_name}){var el=document.querySelector(target);" \
36
+ "if(el){window.#{global_name}(el,config);}}else{schedule();}}" \
37
+ "if(!document.querySelector('script['+marker+']')){" \
38
+ "var s=document.createElement('script');" \
39
+ "s.src=scriptSrc;" \
40
+ "s.setAttribute(marker,'');" \
41
+ "document.head.appendChild(s);" \
42
+ "}" \
43
+ "init();" \
44
+ "})();" \
45
+ "</script>"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,131 @@
1
+ require "liquid"
2
+
3
+ module FastComments
4
+ module Jekyll
5
+ class FastCommentsTag < ContainerTag
6
+ def self.spec
7
+ {
8
+ container_tag: "div", container_id_prefix: "fc",
9
+ script_path: "/js/embed-v2.min.js", script_marker_attr: "data-fc-embed",
10
+ global_name: "FastCommentsUI", page_scoped: true
11
+ }
12
+ end
13
+ end
14
+
15
+ class CommentCountTag < ContainerTag
16
+ def self.spec
17
+ {
18
+ container_tag: "span", container_id_prefix: "fc-count",
19
+ script_path: "/js/widget-comment-count.min.js", script_marker_attr: "data-fc-count",
20
+ global_name: "FastCommentsCommentCount", page_scoped: true
21
+ }
22
+ end
23
+ end
24
+
25
+ class LiveChatTag < ContainerTag
26
+ def self.spec
27
+ {
28
+ container_tag: "div", container_id_prefix: "fc-live-chat",
29
+ script_path: "/js/embed-live-chat.min.js", script_marker_attr: "data-fc-live-chat",
30
+ global_name: "FastCommentsLiveChat", page_scoped: true
31
+ }
32
+ end
33
+ end
34
+
35
+ class CollabChatTag < SelectorTag
36
+ def self.spec
37
+ {
38
+ script_path: "/js/embed-collab-chat.min.js", script_marker_attr: "data-fc-collab-chat",
39
+ global_name: "FastCommentsCollabChat", shortcode_name: "fastcomments_collab_chat",
40
+ page_scoped: true
41
+ }
42
+ end
43
+ end
44
+
45
+ class ImageChatTag < SelectorTag
46
+ def self.spec
47
+ {
48
+ script_path: "/js/embed-image-chat.min.js", script_marker_attr: "data-fc-image-chat",
49
+ global_name: "FastCommentsImageChat", shortcode_name: "fastcomments_image_chat",
50
+ page_scoped: true
51
+ }
52
+ end
53
+ end
54
+
55
+ class RecentCommentsTag < ContainerTag
56
+ def self.spec
57
+ {
58
+ container_tag: "div", container_id_prefix: "fc-recent-comments",
59
+ script_path: "/js/widget-recent-comments-v2.min.js",
60
+ script_marker_attr: "data-fc-recent-comments-v2",
61
+ global_name: "FastCommentsRecentCommentsV2"
62
+ }
63
+ end
64
+ end
65
+
66
+ class RecentDiscussionsTag < ContainerTag
67
+ def self.spec
68
+ {
69
+ container_tag: "div", container_id_prefix: "fc-recent-discussions",
70
+ script_path: "/js/widget-recent-discussions-v2.min.js",
71
+ script_marker_attr: "data-fc-recent-discussions-v2",
72
+ global_name: "FastCommentsRecentDiscussionsV2"
73
+ }
74
+ end
75
+ end
76
+
77
+ class ReviewsSummaryTag < ContainerTag
78
+ def self.spec
79
+ {
80
+ container_tag: "div", container_id_prefix: "fc-rs",
81
+ script_path: "/js/embed-reviews-summary.min.js", script_marker_attr: "data-fc-reviews-summary",
82
+ global_name: "FastCommentsReviewsSummaryWidget",
83
+ use_callback: true, error_label: "Reviews Summary"
84
+ }
85
+ end
86
+ end
87
+
88
+ class TopPagesTag < ContainerTag
89
+ def self.spec
90
+ {
91
+ container_tag: "div", container_id_prefix: "fc-top-pages",
92
+ script_path: "/js/widget-top-pages-v2.min.js", script_marker_attr: "data-fc-top-pages-v2",
93
+ global_name: "FastCommentsTopPagesV2"
94
+ }
95
+ end
96
+ end
97
+
98
+ class UserActivityFeedTag < UserActivityTag
99
+ def self.spec
100
+ {
101
+ container_tag: "div", container_id_prefix: "fc-activity",
102
+ script_path: "/js/embed-user-activity.min.js", script_marker_attr: "data-fc-user-activity",
103
+ global_name: "FastCommentsUserActivity",
104
+ use_callback: true, error_label: "User Activity"
105
+ }
106
+ end
107
+ end
108
+
109
+ class CommentCountBulkTag < BulkCountTag
110
+ def self.spec
111
+ {
112
+ script_path: "/js/embed-widget-comment-count-bulk.min.js",
113
+ script_marker_attr: "data-fc-count-bulk",
114
+ global_name: "FastCommentsBulkCountConfig"
115
+ }
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ ::Liquid::Template.register_tag("fastcomments", FastComments::Jekyll::FastCommentsTag)
122
+ ::Liquid::Template.register_tag("fastcomments_comment_count", FastComments::Jekyll::CommentCountTag)
123
+ ::Liquid::Template.register_tag("fastcomments_comment_count_bulk", FastComments::Jekyll::CommentCountBulkTag)
124
+ ::Liquid::Template.register_tag("fastcomments_live_chat", FastComments::Jekyll::LiveChatTag)
125
+ ::Liquid::Template.register_tag("fastcomments_collab_chat", FastComments::Jekyll::CollabChatTag)
126
+ ::Liquid::Template.register_tag("fastcomments_image_chat", FastComments::Jekyll::ImageChatTag)
127
+ ::Liquid::Template.register_tag("fastcomments_recent_comments", FastComments::Jekyll::RecentCommentsTag)
128
+ ::Liquid::Template.register_tag("fastcomments_recent_discussions", FastComments::Jekyll::RecentDiscussionsTag)
129
+ ::Liquid::Template.register_tag("fastcomments_reviews_summary", FastComments::Jekyll::ReviewsSummaryTag)
130
+ ::Liquid::Template.register_tag("fastcomments_top_pages", FastComments::Jekyll::TopPagesTag)
131
+ ::Liquid::Template.register_tag("fastcomments_user_activity_feed", FastComments::Jekyll::UserActivityFeedTag)
@@ -0,0 +1,59 @@
1
+ require "json"
2
+ require "securerandom"
3
+
4
+ module FastComments
5
+ module Jekyll
6
+ # Low-level helpers ported from the fastcomments-11ty util.ts so the emitted
7
+ # client JS is byte-equivalent.
8
+ module Util
9
+ module_function
10
+
11
+ ESCAPE_FOR_SCRIPT = {
12
+ "<" => "\\u003C",
13
+ ">" => "\\u003E",
14
+ "&" => "\\u0026",
15
+ "
" => "\\u2028",
16
+ "
" => "\\u2029"
17
+ }.freeze
18
+
19
+ # Escape the characters that can break out of an inline <script> body.
20
+ def escape_for_script(str)
21
+ str.to_s.gsub(/[<>&

]/) { |c| ESCAPE_FOR_SCRIPT[c] }
22
+ end
23
+
24
+ # Escape a value for use inside a double-quoted HTML attribute (& first).
25
+ def escape_attr(value)
26
+ value.to_s
27
+ .gsub("&", "&amp;")
28
+ .gsub('"', "&quot;")
29
+ .gsub("<", "&lt;")
30
+ .gsub(">", "&gt;")
31
+ end
32
+
33
+ # JSON-encode a value for safe embedding in an inline <script>.
34
+ def json_for_script(value)
35
+ escape_for_script(JSON.generate(value))
36
+ end
37
+
38
+ def get_cdn_base(region)
39
+ region.to_s == "eu" ? "https://cdn-eu.fastcomments.com" : "https://cdn.fastcomments.com"
40
+ end
41
+
42
+ # Drop nil values; keep scalars/arrays/hashes (mirrors the TS sanitizeConfig).
43
+ def sanitize_config(config)
44
+ return {} unless config.is_a?(Hash)
45
+
46
+ config.each_with_object({}) do |(key, value), out|
47
+ next if value.nil?
48
+
49
+ out[key] = value
50
+ end
51
+ end
52
+
53
+ # Container ids only need to be unique within a page.
54
+ def make_container_id(prefix)
55
+ "#{prefix}-#{SecureRandom.alphanumeric(7).downcase}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module FastComments
2
+ module Jekyll
3
+ VERSION = "1.0.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "fastcomments/version"
2
+ require "fastcomments/jekyll/util"
3
+ require "fastcomments/jekyll/key_mapper"
4
+ require "fastcomments/jekyll/attribute_parser"
5
+ require "fastcomments/jekyll/config_resolver"
6
+ require "fastcomments/jekyll/container_widget"
7
+ require "fastcomments/jekyll/selector_widget"
8
+ require "fastcomments/jekyll/bulk_count_widget"
9
+ require "fastcomments/jekyll/base_tag"
10
+ require "fastcomments/jekyll/tags"
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastcomments-jekyll
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - FastComments
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ description: Liquid tags for embedding FastComments widgets (comments, live chat,
48
+ collab/image chat, reviews summary, recent comments/discussions, top pages, and
49
+ user activity feed) into Jekyll sites.
50
+ email:
51
+ - support@fastcomments.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - CHANGELOG.md
57
+ - LICENSE
58
+ - README.md
59
+ - lib/fastcomments-jekyll.rb
60
+ - lib/fastcomments/jekyll/attribute_parser.rb
61
+ - lib/fastcomments/jekyll/base_tag.rb
62
+ - lib/fastcomments/jekyll/bulk_count_widget.rb
63
+ - lib/fastcomments/jekyll/config_resolver.rb
64
+ - lib/fastcomments/jekyll/container_widget.rb
65
+ - lib/fastcomments/jekyll/key_mapper.rb
66
+ - lib/fastcomments/jekyll/selector_widget.rb
67
+ - lib/fastcomments/jekyll/tags.rb
68
+ - lib/fastcomments/jekyll/util.rb
69
+ - lib/fastcomments/version.rb
70
+ homepage: https://docs.fastcomments.com/guide-lib-jekyll.html
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ source_code_uri: https://github.com/FastComments/fastcomments-jekyll
75
+ homepage_uri: https://docs.fastcomments.com/guide-lib-jekyll.html
76
+ changelog_uri: https://github.com/FastComments/fastcomments-jekyll/blob/main/CHANGELOG.md
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '3.0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.4.20
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Jekyll plugin for FastComments, a live commenting system.
96
+ test_files: []