al_comments 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +20 -0
- data/README.md +36 -0
- data/lib/al_comments.rb +127 -0
- metadata +125 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a8582e0b0a66b49c71cafbf872b834a2154e5221f8dc1520aac1b34b0e3fbbf8
|
|
4
|
+
data.tar.gz: 0fb8762fba4a9e91594be452e2584ff47726d9c41b5aeea8b91ccce4bf9f52a5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8cd9477e85aecc152ac1ef75dd40d6663de2ff54835d41b435128893752f1d45586481a443ed07898adc66813207747b365ee0e73021b591a5067c916097ad0f
|
|
7
|
+
data.tar.gz: 9d66f7bfd9f311fa5dfe9811a65329b3817f4ab7d6c6184352bae96e5fe5c05db95b4b5c06e775e90fe92b5d4aa92fb3b682b241fa4a2f03374317daa84ca956
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Maruan Al-Shedivat.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Al-Comments
|
|
2
|
+
|
|
3
|
+
A Jekyll plugin that provides reusable comment integrations for al-folio-compatible themes.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Giscus comments
|
|
8
|
+
- Disqus comments
|
|
9
|
+
- Theme-aware Giscus setup
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this to your `Gemfile`:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'al_comments'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then run:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Enable in `_config.yml`:
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
plugins:
|
|
29
|
+
- al_comments
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Render comments where needed:
|
|
33
|
+
|
|
34
|
+
```liquid
|
|
35
|
+
{% al_comments %}
|
|
36
|
+
```
|
data/lib/al_comments.rb
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'jekyll'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module AlComments
|
|
5
|
+
class CommentsTag < Liquid::Tag
|
|
6
|
+
def render(context)
|
|
7
|
+
site = context.registers[:site]
|
|
8
|
+
return '' unless site
|
|
9
|
+
|
|
10
|
+
page = context.registers[:page] || context['page'] || {}
|
|
11
|
+
output = []
|
|
12
|
+
|
|
13
|
+
if site.config['disqus_shortname'] && truthy?(page['disqus_comments'])
|
|
14
|
+
output << disqus_html(site, page)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if truthy?(page['giscus_comments'])
|
|
18
|
+
output << giscus_html(site, page)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
output.join("\n")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def truthy?(value)
|
|
27
|
+
value == true || value.to_s == 'true'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def post_layout?(page)
|
|
31
|
+
page['layout'].to_s == 'post'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def disqus_html(site, page)
|
|
35
|
+
<<~HTML
|
|
36
|
+
<div id="disqus_thread" style="max-width: #{site.config['max_width']}; margin: 0 auto;">
|
|
37
|
+
<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};
|
|
41
|
+
(function() {
|
|
42
|
+
var dsq = document.createElement('script');
|
|
43
|
+
dsq.type = 'text/javascript';
|
|
44
|
+
dsq.async = true;
|
|
45
|
+
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
|
|
46
|
+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
|
47
|
+
})();
|
|
48
|
+
</script>
|
|
49
|
+
<noscript>
|
|
50
|
+
Please enable JavaScript to view the
|
|
51
|
+
<a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
|
|
52
|
+
</noscript>
|
|
53
|
+
</div>
|
|
54
|
+
HTML
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
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;\"" : ''
|
|
60
|
+
spacer = post_layout?(page) ? "\n <br>" : ''
|
|
61
|
+
|
|
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>)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
<<~HTML
|
|
72
|
+
<div id="giscus_thread"#{style}>#{spacer}
|
|
73
|
+
<script>
|
|
74
|
+
(function setupGiscus() {
|
|
75
|
+
function determineGiscusTheme() {
|
|
76
|
+
#{theme_detection(site)}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var giscusTheme = determineGiscusTheme();
|
|
80
|
+
var attrs = {
|
|
81
|
+
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},
|
|
91
|
+
"data-theme": giscusTheme,
|
|
92
|
+
"data-lang": #{giscus['lang'].to_s.to_json},
|
|
93
|
+
crossorigin: "anonymous",
|
|
94
|
+
async: true
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
var giscusScript = document.createElement("script");
|
|
98
|
+
Object.entries(attrs).forEach(function(entry) { giscusScript.setAttribute(entry[0], entry[1]); });
|
|
99
|
+
var host = document.getElementById("giscus_thread");
|
|
100
|
+
if (host) host.appendChild(giscusScript);
|
|
101
|
+
})();
|
|
102
|
+
</script>
|
|
103
|
+
<noscript>
|
|
104
|
+
Please enable JavaScript to view the
|
|
105
|
+
<a href="http://giscus.app/?ref_noscript">comments powered by giscus.</a>
|
|
106
|
+
</noscript>
|
|
107
|
+
</div>
|
|
108
|
+
HTML
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def theme_detection(site)
|
|
112
|
+
if site.config['enable_darkmode']
|
|
113
|
+
<<~JS
|
|
114
|
+
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};
|
|
117
|
+
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};
|
|
119
|
+
JS
|
|
120
|
+
else
|
|
121
|
+
%(return #{site.config.dig('giscus', 'light_theme').to_s.to_json};)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
Liquid::Template.register_tag('al_comments', AlComments::CommentsTag)
|
metadata
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: al_comments
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- al-org
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-02-07 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.9'
|
|
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.9'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: liquid
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '4.0'
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '6.0'
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '4.0'
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '6.0'
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: bundler
|
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '2.0'
|
|
60
|
+
- - "<"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '3.0'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '2.0'
|
|
70
|
+
- - "<"
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '3.0'
|
|
73
|
+
- !ruby/object:Gem::Dependency
|
|
74
|
+
name: rake
|
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - "~>"
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '13.0'
|
|
80
|
+
type: :development
|
|
81
|
+
prerelease: false
|
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - "~>"
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '13.0'
|
|
87
|
+
description: Jekyll plugin extracted from al-folio that renders theme-aware Giscus
|
|
88
|
+
and Disqus comment blocks via a reusable Liquid tag.
|
|
89
|
+
email:
|
|
90
|
+
- dev@al-org.dev
|
|
91
|
+
executables: []
|
|
92
|
+
extensions: []
|
|
93
|
+
extra_rdoc_files: []
|
|
94
|
+
files:
|
|
95
|
+
- CHANGELOG.md
|
|
96
|
+
- LICENSE
|
|
97
|
+
- README.md
|
|
98
|
+
- lib/al_comments.rb
|
|
99
|
+
homepage: https://github.com/al-org-dev/al-comments
|
|
100
|
+
licenses:
|
|
101
|
+
- MIT
|
|
102
|
+
metadata:
|
|
103
|
+
allowed_push_host: https://rubygems.org
|
|
104
|
+
homepage_uri: https://github.com/al-org-dev/al-comments
|
|
105
|
+
source_code_uri: https://github.com/al-org-dev/al-comments
|
|
106
|
+
post_install_message:
|
|
107
|
+
rdoc_options: []
|
|
108
|
+
require_paths:
|
|
109
|
+
- lib
|
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '2.7'
|
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - ">="
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0'
|
|
120
|
+
requirements: []
|
|
121
|
+
rubygems_version: 3.0.3.1
|
|
122
|
+
signing_key:
|
|
123
|
+
specification_version: 4
|
|
124
|
+
summary: Giscus and Disqus comments tag for Jekyll sites
|
|
125
|
+
test_files: []
|