al_comments 0.1.0 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/al_comments.rb +110 -34
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 48a78c929e423ff284d9ddb31ad8c7ee322f50394452c42bdabe0bb543b92c02
|
|
4
|
+
data.tar.gz: 7d5ff7dd4a7ea88fe64d782b6228398c23aafd1ad4bea83f484e961f0663e910
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cef6fcfdf238069a461a198a2deddb9610238b4fed2671f458a9214a07444e106549ec26864d955bd7c9e35efd8134bceb2c341aeac31e9619c3097a1e24c93
|
|
7
|
+
data.tar.gz: 6d2f0e1b0207ebef63884c4ad23f30975eff9b45a304073fc1504f8152033d28335e716e0d52e41492e73419c26b4e27283a52b9d862dd3a0a8131e8e1d73afd
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1 - 2026-02-07
|
|
4
|
+
- Improved config compatibility for comment rendering:
|
|
5
|
+
- Supports both string and symbol keys for nested config values.
|
|
6
|
+
- Supports `disqus.shortname` in addition to `disqus_shortname`.
|
|
7
|
+
- Supports `giscus.repo` aliases and fallback from `repository` / `github.repository_nwo`.
|
|
8
|
+
- Accepts common truthy flag values (`1`, `yes`, `on`) for `*_comments`.
|
|
9
|
+
- Added automated tests for Giscus/Disqus rendering paths and config fallbacks.
|
|
10
|
+
|
|
3
11
|
## 0.1.0 - 2026-02-07
|
|
4
12
|
- Initial gem release.
|
|
5
13
|
- Added standalone Giscus/Disqus comment rendering tag for Jekyll/al-folio sites.
|
data/lib/al_comments.rb
CHANGED
|
@@ -9,12 +9,13 @@ module AlComments
|
|
|
9
9
|
|
|
10
10
|
page = context.registers[:page] || context['page'] || {}
|
|
11
11
|
output = []
|
|
12
|
+
disqus_shortname = resolve_disqus_shortname(site)
|
|
12
13
|
|
|
13
|
-
if
|
|
14
|
-
output << disqus_html(site, page)
|
|
14
|
+
if disqus_shortname && truthy?(fetch_key(page, 'disqus_comments'))
|
|
15
|
+
output << disqus_html(site, page, disqus_shortname)
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
if truthy?(page
|
|
18
|
+
if truthy?(fetch_key(page, 'giscus_comments'))
|
|
18
19
|
output << giscus_html(site, page)
|
|
19
20
|
end
|
|
20
21
|
|
|
@@ -24,20 +25,86 @@ module AlComments
|
|
|
24
25
|
private
|
|
25
26
|
|
|
26
27
|
def truthy?(value)
|
|
27
|
-
|
|
28
|
+
return false if value.nil? || value == false
|
|
29
|
+
return true if value == true
|
|
30
|
+
return true if value.is_a?(Numeric) && value != 0
|
|
31
|
+
|
|
32
|
+
normalized = value.to_s.strip.downcase
|
|
33
|
+
%w[true 1 yes y on].include?(normalized)
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def post_layout?(page)
|
|
31
|
-
page
|
|
37
|
+
fetch_key(page, 'layout').to_s == 'post'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def fetch_key(hash, *keys)
|
|
41
|
+
return nil unless hash.respond_to?(:key?)
|
|
42
|
+
|
|
43
|
+
keys.each do |key|
|
|
44
|
+
return hash[key] if hash.key?(key)
|
|
45
|
+
|
|
46
|
+
string_key = key.to_s
|
|
47
|
+
return hash[string_key] if hash.key?(string_key)
|
|
48
|
+
|
|
49
|
+
symbol_key = key.respond_to?(:to_sym) ? key.to_sym : nil
|
|
50
|
+
return hash[symbol_key] if symbol_key && hash.key?(symbol_key)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def value_blank?(value)
|
|
57
|
+
value.nil? || value.to_s.strip.empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def resolve_disqus_shortname(site)
|
|
61
|
+
direct = fetch_key(site.config, 'disqus_shortname')
|
|
62
|
+
return direct.to_s unless value_blank?(direct)
|
|
63
|
+
|
|
64
|
+
disqus = fetch_key(site.config, 'disqus')
|
|
65
|
+
return nil unless disqus.is_a?(Hash)
|
|
66
|
+
|
|
67
|
+
nested = fetch_key(disqus, 'shortname')
|
|
68
|
+
return nil if value_blank?(nested)
|
|
69
|
+
|
|
70
|
+
nested.to_s
|
|
32
71
|
end
|
|
33
72
|
|
|
34
|
-
def
|
|
73
|
+
def resolve_giscus_config(site)
|
|
74
|
+
giscus = fetch_key(site.config, 'giscus')
|
|
75
|
+
return giscus if giscus.is_a?(Hash)
|
|
76
|
+
|
|
77
|
+
comments = fetch_key(site.config, 'comments')
|
|
78
|
+
return {} unless comments.is_a?(Hash)
|
|
79
|
+
|
|
80
|
+
nested = fetch_key(comments, 'giscus')
|
|
81
|
+
nested.is_a?(Hash) ? nested : {}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def resolve_giscus_repo(site, giscus)
|
|
85
|
+
repo = fetch_key(giscus, 'repo', 'repository', 'repo_name')
|
|
86
|
+
return repo.to_s unless value_blank?(repo)
|
|
87
|
+
|
|
88
|
+
repository = fetch_key(site.config, 'repository')
|
|
89
|
+
return repository.to_s unless value_blank?(repository)
|
|
90
|
+
|
|
91
|
+
github = fetch_key(site.config, 'github')
|
|
92
|
+
if github.is_a?(Hash)
|
|
93
|
+
repository_nwo = fetch_key(github, 'repository_nwo')
|
|
94
|
+
return repository_nwo.to_s unless value_blank?(repository_nwo)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
''
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def disqus_html(site, page, disqus_shortname)
|
|
101
|
+
max_width = fetch_key(site.config, 'max_width')
|
|
35
102
|
<<~HTML
|
|
36
|
-
<div id="disqus_thread" style="max-width: #{
|
|
103
|
+
<div id="disqus_thread" style="max-width: #{max_width}; margin: 0 auto;">
|
|
37
104
|
<script type="text/javascript">
|
|
38
|
-
var disqus_shortname = #{
|
|
39
|
-
var disqus_identifier = #{page
|
|
40
|
-
var disqus_title = #{page
|
|
105
|
+
var disqus_shortname = #{disqus_shortname.to_json};
|
|
106
|
+
var disqus_identifier = #{fetch_key(page, 'id').to_s.to_json};
|
|
107
|
+
var disqus_title = #{fetch_key(page, 'title').to_s.to_json};
|
|
41
108
|
(function() {
|
|
42
109
|
var dsq = document.createElement('script');
|
|
43
110
|
dsq.type = 'text/javascript';
|
|
@@ -55,17 +122,20 @@ module AlComments
|
|
|
55
122
|
end
|
|
56
123
|
|
|
57
124
|
def giscus_html(site, page)
|
|
58
|
-
giscus = site
|
|
59
|
-
|
|
125
|
+
giscus = resolve_giscus_config(site)
|
|
126
|
+
repo = resolve_giscus_repo(site, giscus)
|
|
127
|
+
max_width = fetch_key(site.config, 'max_width')
|
|
128
|
+
style = post_layout?(page) ? " style=\"max-width: #{max_width}; margin: 0 auto;\"" : ''
|
|
60
129
|
spacer = post_layout?(page) ? "\n <br>" : ''
|
|
61
130
|
|
|
62
|
-
if
|
|
63
|
-
warning = <<~
|
|
64
|
-
>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
131
|
+
if repo.to_s.strip.empty?
|
|
132
|
+
warning = <<~HTML
|
|
133
|
+
<blockquote class="block-danger">
|
|
134
|
+
<h5>giscus comments misconfigured</h5>
|
|
135
|
+
<p>Please follow instructions at <a href="http://giscus.app">http://giscus.app</a> and update your giscus configuration.</p>
|
|
136
|
+
</blockquote>
|
|
137
|
+
HTML
|
|
138
|
+
return %(<div id="giscus_thread"#{style}>#{spacer}\n#{warning}</div>)
|
|
69
139
|
end
|
|
70
140
|
|
|
71
141
|
<<~HTML
|
|
@@ -79,17 +149,17 @@ module AlComments
|
|
|
79
149
|
var giscusTheme = determineGiscusTheme();
|
|
80
150
|
var attrs = {
|
|
81
151
|
src: "https://giscus.app/client.js",
|
|
82
|
-
"data-repo": #{
|
|
83
|
-
"data-repo-id": #{giscus
|
|
84
|
-
"data-category": #{giscus
|
|
85
|
-
"data-category-id": #{giscus
|
|
86
|
-
"data-mapping": #{giscus
|
|
87
|
-
"data-strict": #{giscus
|
|
88
|
-
"data-reactions-enabled": #{giscus
|
|
89
|
-
"data-emit-metadata": #{giscus
|
|
90
|
-
"data-input-position": #{giscus
|
|
152
|
+
"data-repo": #{repo.to_s.to_json},
|
|
153
|
+
"data-repo-id": #{fetch_key(giscus, 'repo_id').to_s.to_json},
|
|
154
|
+
"data-category": #{fetch_key(giscus, 'category').to_s.to_json},
|
|
155
|
+
"data-category-id": #{fetch_key(giscus, 'category_id').to_s.to_json},
|
|
156
|
+
"data-mapping": #{fetch_key(giscus, 'mapping').to_s.to_json},
|
|
157
|
+
"data-strict": #{fetch_key(giscus, 'strict').to_s.to_json},
|
|
158
|
+
"data-reactions-enabled": #{fetch_key(giscus, 'reactions_enabled').to_s.to_json},
|
|
159
|
+
"data-emit-metadata": #{fetch_key(giscus, 'emit_metadata').to_s.to_json},
|
|
160
|
+
"data-input-position": #{fetch_key(giscus, 'input_position').to_s.to_json},
|
|
91
161
|
"data-theme": giscusTheme,
|
|
92
|
-
"data-lang": #{giscus
|
|
162
|
+
"data-lang": #{fetch_key(giscus, 'lang').to_s.to_json},
|
|
93
163
|
crossorigin: "anonymous",
|
|
94
164
|
async: true
|
|
95
165
|
};
|
|
@@ -109,16 +179,22 @@ module AlComments
|
|
|
109
179
|
end
|
|
110
180
|
|
|
111
181
|
def theme_detection(site)
|
|
112
|
-
|
|
182
|
+
giscus = resolve_giscus_config(site)
|
|
183
|
+
dark_theme = fetch_key(giscus, 'dark_theme').to_s
|
|
184
|
+
light_theme = fetch_key(giscus, 'light_theme').to_s
|
|
185
|
+
dark_theme = 'dark' if value_blank?(dark_theme)
|
|
186
|
+
light_theme = 'light' if value_blank?(light_theme)
|
|
187
|
+
|
|
188
|
+
if fetch_key(site.config, 'enable_darkmode')
|
|
113
189
|
<<~JS
|
|
114
190
|
var theme = localStorage.getItem("theme") || document.documentElement.getAttribute("data-theme") || "system";
|
|
115
|
-
if (theme === "dark") return #{
|
|
116
|
-
if (theme === "light") return #{
|
|
191
|
+
if (theme === "dark") return #{dark_theme.to_json};
|
|
192
|
+
if (theme === "light") return #{light_theme.to_json};
|
|
117
193
|
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
118
|
-
return prefersDark ? #{
|
|
194
|
+
return prefersDark ? #{dark_theme.to_json} : #{light_theme.to_json};
|
|
119
195
|
JS
|
|
120
196
|
else
|
|
121
|
-
%(return #{
|
|
197
|
+
%(return #{light_theme.to_json};)
|
|
122
198
|
end
|
|
123
199
|
end
|
|
124
200
|
end
|