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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/lib/al_comments.rb +110 -34
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8582e0b0a66b49c71cafbf872b834a2154e5221f8dc1520aac1b34b0e3fbbf8
4
- data.tar.gz: 0fb8762fba4a9e91594be452e2584ff47726d9c41b5aeea8b91ccce4bf9f52a5
3
+ metadata.gz: 48a78c929e423ff284d9ddb31ad8c7ee322f50394452c42bdabe0bb543b92c02
4
+ data.tar.gz: 7d5ff7dd4a7ea88fe64d782b6228398c23aafd1ad4bea83f484e961f0663e910
5
5
  SHA512:
6
- metadata.gz: 8cd9477e85aecc152ac1ef75dd40d6663de2ff54835d41b435128893752f1d45586481a443ed07898adc66813207747b365ee0e73021b591a5067c916097ad0f
7
- data.tar.gz: 9d66f7bfd9f311fa5dfe9811a65329b3817f4ab7d6c6184352bae96e5fe5c05db95b4b5c06e775e90fe92b5d4aa92fb3b682b241fa4a2f03374317daa84ca956
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 site.config['disqus_shortname'] && truthy?(page['disqus_comments'])
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['giscus_comments'])
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
- value == true || value.to_s == 'true'
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['layout'].to_s == 'post'
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 disqus_html(site, page)
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: #{site.config['max_width']}; margin: 0 auto;">
103
+ <div id="disqus_thread" style="max-width: #{max_width}; margin: 0 auto;">
37
104
  <script type="text/javascript">
38
- var disqus_shortname = #{site.config['disqus_shortname'].to_json};
39
- var disqus_identifier = #{page['id'].to_s.to_json};
40
- var disqus_title = #{page['title'].to_s.to_json};
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.config['giscus'] || {}
59
- style = post_layout?(page) ? " style=\"max-width: #{site.config['max_width']}; margin: 0 auto;\"" : ''
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 giscus['repo'].to_s.strip.empty?
63
- warning = <<~MARKDOWN
64
- > ##### giscus comments misconfigured
65
- > Please follow instructions at [http://giscus.app](http://giscus.app) and update your giscus configuration.
66
- {: .block-danger }
67
- MARKDOWN
68
- return %(<div id="giscus_thread"#{style}>#{spacer}\n#{Jekyll::Converters::Markdown.new(site.config).convert(warning)}</div>)
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": #{giscus['repo'].to_s.to_json},
83
- "data-repo-id": #{giscus['repo_id'].to_s.to_json},
84
- "data-category": #{giscus['category'].to_s.to_json},
85
- "data-category-id": #{giscus['category_id'].to_s.to_json},
86
- "data-mapping": #{giscus['mapping'].to_s.to_json},
87
- "data-strict": #{giscus['strict'].to_s.to_json},
88
- "data-reactions-enabled": #{giscus['reactions_enabled'].to_s.to_json},
89
- "data-emit-metadata": #{giscus['emit_metadata'].to_s.to_json},
90
- "data-input-position": #{giscus['input_position'].to_s.to_json},
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['lang'].to_s.to_json},
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
- if site.config['enable_darkmode']
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 #{site.config.dig('giscus', 'dark_theme').to_s.to_json};
116
- if (theme === "light") return #{site.config.dig('giscus', 'light_theme').to_s.to_json};
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 ? #{site.config.dig('giscus', 'dark_theme').to_s.to_json} : #{site.config.dig('giscus', 'light_theme').to_s.to_json};
194
+ return prefersDark ? #{dark_theme.to_json} : #{light_theme.to_json};
119
195
  JS
120
196
  else
121
- %(return #{site.config.dig('giscus', 'light_theme').to_s.to_json};)
197
+ %(return #{light_theme.to_json};)
122
198
  end
123
199
  end
124
200
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: al_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - al-org