toottown 0.2.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: b52297c595a4a4bded83dc3361ab8157991eaaca4018bd338a4b9f993fc355e4
4
+ data.tar.gz: cb72b3b0050c2874fa18bfc85e0d83e95f6aaf3f9e4298ab4717a55dc3024d0d
5
+ SHA512:
6
+ metadata.gz: 2a3660b34c646c8e4ba0e319cd67217b7fef39da93d09ed272cf9ec3fa24b0a17fbd236b4b37aa9e50d415fee405ebcefa634522e130758bd1549e1ad2490bc7
7
+ data.tar.gz: 3170775c36ecb9a7d4c1b07d44709847fdb4673524727b83d00079a065df6a3ed1d1090b1ba6ed7609ff1e20f69b015faeb825247e2a26155c09c9020a65d14d
@@ -0,0 +1,32 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - "*"
7
+ push:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby_version: [2.7.7, 3.0.5, 3.1.3, 3.2.0]
17
+ bridgetown_version: [1.2.0]
18
+ continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
19
+ # Has to be top level to cache properly
20
+ env:
21
+ BUNDLE_JOBS: 3
22
+ BUNDLE_PATH: "vendor/bundle"
23
+ BRIDGETOWN_VERSION: ${{ matrix.bridgetown_version }}
24
+ steps:
25
+ - uses: actions/checkout@master
26
+ - name: Setup Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby_version }}
30
+ bundler-cache: true
31
+ - name: Test with Rake
32
+ run: script/cibuild
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+ .bundle
17
+
18
+ # Node
19
+ node_modules
20
+ .npm
21
+ .node_repl_history
22
+
23
+ # Yarn
24
+ yarn-error.log
25
+ yarn-debug.log*
26
+ .pnp/
27
+ .pnp.js
28
+
29
+ # Yarn Integrity file
30
+ .yarn-integrity
31
+
32
+ test/dest
33
+ .bridgetown-metadata
34
+ .bridgetown-cache
35
+ .bridgetown-webpack
36
+
37
+ .env
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require: rubocop-bridgetown
2
+
3
+ inherit_gem:
4
+ rubocop-bridgetown: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 3.1
8
+
9
+ Exclude:
10
+ - .gitignore
11
+ - .rubocop.yml
12
+ - "*.gemspec"
13
+
14
+ - Gemfile.lock
15
+ - CHANGELOG.md
16
+ - LICENSE.txt
17
+ - README.md
18
+ - Rakefile
19
+ - bridgetown.automation.rb
20
+
21
+ - script/**/*
22
+ - test/fixtures/**/*
23
+ - vendor/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ - ...
11
+
12
+ ## [0.2.0] - 2025-10-07
13
+
14
+ - Migrate project to Codeberg
15
+
16
+ ## [0.1.0] - 2023
17
+
18
+ - First version
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
7
+
8
+ group :test do
9
+ gem "rack-test"
10
+ gem "minitest"
11
+ gem "minitest-profile"
12
+ gem "minitest-reporters"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,238 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ toottown (0.2.0)
5
+ bridgetown (>= 2.0)
6
+ phlex (~> 1.3)
7
+ redis (~> 5.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (7.2.2.2)
13
+ base64
14
+ benchmark (>= 0.3)
15
+ bigdecimal
16
+ concurrent-ruby (~> 1.0, >= 1.3.1)
17
+ connection_pool (>= 2.2.5)
18
+ drb
19
+ i18n (>= 1.6, < 2)
20
+ logger (>= 1.4.2)
21
+ minitest (>= 5.1)
22
+ securerandom (>= 0.3)
23
+ tzinfo (~> 2.0, >= 2.0.5)
24
+ addressable (2.8.7)
25
+ public_suffix (>= 2.0.2, < 7.0)
26
+ amazing_print (1.8.1)
27
+ ansi (1.5.0)
28
+ ast (2.4.3)
29
+ base64 (0.3.0)
30
+ benchmark (0.4.1)
31
+ bigdecimal (3.3.0)
32
+ bridgetown (2.0.1)
33
+ bridgetown-builder (= 2.0.1)
34
+ bridgetown-core (= 2.0.1)
35
+ bridgetown-foundation (= 2.0.1)
36
+ bridgetown-paginate (= 2.0.1)
37
+ bridgetown-builder (2.0.1)
38
+ bridgetown-core (= 2.0.1)
39
+ bridgetown-core (2.0.1)
40
+ activesupport (>= 6.0, < 8.0)
41
+ addressable (~> 2.4)
42
+ amazing_print (~> 1.2)
43
+ bridgetown-foundation (= 2.0.1)
44
+ csv (~> 3.2)
45
+ dry-inflector (>= 1.0)
46
+ erubi (~> 1.9)
47
+ faraday (~> 2.0)
48
+ faraday-follow_redirects (~> 0.3)
49
+ i18n (~> 1.0)
50
+ irb (>= 1.14)
51
+ kramdown (~> 2.1)
52
+ kramdown-parser-gfm (~> 1.0)
53
+ liquid (>= 5.0, < 5.5)
54
+ listen (~> 3.0)
55
+ rack (>= 3.0)
56
+ rackup (~> 2.0)
57
+ rake (>= 13.0)
58
+ roda (~> 3.46)
59
+ rouge (>= 3.0, < 5.0)
60
+ serbea (~> 2.1)
61
+ signalize (~> 1.3)
62
+ streamlined (>= 0.6.0)
63
+ thor (~> 1.1)
64
+ tilt (~> 2.0)
65
+ zeitwerk (~> 2.5)
66
+ bridgetown-foundation (2.0.1)
67
+ hash_with_dot_access (~> 2.0)
68
+ inclusive (~> 1.0)
69
+ zeitwerk (~> 2.5)
70
+ bridgetown-paginate (2.0.1)
71
+ bridgetown-core (= 2.0.1)
72
+ builder (3.3.0)
73
+ concurrent-ruby (1.3.5)
74
+ connection_pool (2.5.4)
75
+ csv (3.3.5)
76
+ date (3.4.1)
77
+ dotenv (2.8.1)
78
+ drb (2.2.3)
79
+ dry-inflector (1.2.0)
80
+ erb (5.0.3)
81
+ erubi (1.13.1)
82
+ faraday (2.14.0)
83
+ faraday-net_http (>= 2.0, < 3.5)
84
+ json
85
+ logger
86
+ faraday-follow_redirects (0.4.0)
87
+ faraday (>= 1, < 3)
88
+ faraday-net_http (3.4.1)
89
+ net-http (>= 0.5.0)
90
+ ffi (1.17.2)
91
+ ffi (1.17.2-aarch64-linux-gnu)
92
+ ffi (1.17.2-aarch64-linux-musl)
93
+ ffi (1.17.2-arm-linux-gnu)
94
+ ffi (1.17.2-arm-linux-musl)
95
+ ffi (1.17.2-arm64-darwin)
96
+ ffi (1.17.2-x86-linux-gnu)
97
+ ffi (1.17.2-x86-linux-musl)
98
+ ffi (1.17.2-x86_64-darwin)
99
+ ffi (1.17.2-x86_64-linux-gnu)
100
+ ffi (1.17.2-x86_64-linux-musl)
101
+ hash_with_dot_access (2.2.0)
102
+ i18n (1.14.7)
103
+ concurrent-ruby (~> 1.0)
104
+ inclusive (1.1.0)
105
+ io-console (0.8.1)
106
+ irb (1.15.2)
107
+ pp (>= 0.6.0)
108
+ rdoc (>= 4.0.0)
109
+ reline (>= 0.4.2)
110
+ json (2.15.1)
111
+ kramdown (2.5.1)
112
+ rexml (>= 3.3.9)
113
+ kramdown-parser-gfm (1.1.0)
114
+ kramdown (~> 2.0)
115
+ language_server-protocol (3.17.0.5)
116
+ lint_roller (1.1.0)
117
+ liquid (5.4.0)
118
+ listen (3.9.0)
119
+ rb-fsevent (~> 0.10, >= 0.10.3)
120
+ rb-inotify (~> 0.9, >= 0.9.10)
121
+ logger (1.7.0)
122
+ minitest (5.25.5)
123
+ minitest-profile (0.0.2)
124
+ minitest-reporters (1.7.1)
125
+ ansi
126
+ builder
127
+ minitest (>= 5.0)
128
+ ruby-progressbar
129
+ net-http (0.6.0)
130
+ uri
131
+ parallel (1.27.0)
132
+ parser (3.3.9.0)
133
+ ast (~> 2.4.1)
134
+ racc
135
+ phlex (1.11.0)
136
+ pp (0.6.3)
137
+ prettyprint
138
+ prettyprint (0.2.0)
139
+ prism (1.5.1)
140
+ psych (5.2.6)
141
+ date
142
+ stringio
143
+ public_suffix (6.0.2)
144
+ racc (1.8.1)
145
+ rack (3.2.2)
146
+ rack-test (2.2.0)
147
+ rack (>= 1.3)
148
+ rackup (2.2.1)
149
+ rack (>= 3)
150
+ rainbow (3.1.1)
151
+ rake (13.3.0)
152
+ rb-fsevent (0.11.2)
153
+ rb-inotify (0.11.1)
154
+ ffi (~> 1.0)
155
+ rdoc (6.15.0)
156
+ erb
157
+ psych (>= 4.0.0)
158
+ tsort
159
+ redis (5.4.1)
160
+ redis-client (>= 0.22.0)
161
+ redis-client (0.26.1)
162
+ connection_pool
163
+ regexp_parser (2.11.3)
164
+ reline (0.6.2)
165
+ io-console (~> 0.5)
166
+ rexml (3.4.4)
167
+ roda (3.96.0)
168
+ rack
169
+ rouge (4.6.1)
170
+ rubocop (1.81.1)
171
+ json (~> 2.3)
172
+ language_server-protocol (~> 3.17.0.2)
173
+ lint_roller (~> 1.1.0)
174
+ parallel (~> 1.10)
175
+ parser (>= 3.3.0.2)
176
+ rainbow (>= 2.2.2, < 4.0)
177
+ regexp_parser (>= 2.9.3, < 3.0)
178
+ rubocop-ast (>= 1.47.1, < 2.0)
179
+ ruby-progressbar (~> 1.7)
180
+ unicode-display_width (>= 2.4.0, < 4.0)
181
+ rubocop-ast (1.47.1)
182
+ parser (>= 3.3.7.2)
183
+ prism (~> 1.4)
184
+ rubocop-bridgetown (0.6.1)
185
+ rubocop (~> 1.23)
186
+ rubocop-performance (~> 1.12)
187
+ rubocop-performance (1.26.0)
188
+ lint_roller (~> 1.1)
189
+ rubocop (>= 1.75.0, < 2.0)
190
+ rubocop-ast (>= 1.44.0, < 2.0)
191
+ ruby-progressbar (1.13.0)
192
+ securerandom (0.4.1)
193
+ serbea (2.3.0)
194
+ erubi (>= 1.11)
195
+ tilt (>= 2.1)
196
+ signalize (1.3.1)
197
+ concurrent-ruby (~> 1.2)
198
+ streamlined (0.6.1)
199
+ serbea (>= 2.1)
200
+ zeitwerk (~> 2.5)
201
+ stringio (3.1.7)
202
+ thor (1.4.0)
203
+ tilt (2.6.1)
204
+ tsort (0.2.0)
205
+ tzinfo (2.0.6)
206
+ concurrent-ruby (~> 1.0)
207
+ unicode-display_width (3.2.0)
208
+ unicode-emoji (~> 4.1)
209
+ unicode-emoji (4.1.0)
210
+ uri (1.0.4)
211
+ zeitwerk (2.7.3)
212
+
213
+ PLATFORMS
214
+ aarch64-linux-gnu
215
+ aarch64-linux-musl
216
+ arm-linux-gnu
217
+ arm-linux-musl
218
+ arm64-darwin
219
+ ruby
220
+ x86-linux-gnu
221
+ x86-linux-musl
222
+ x86_64-darwin
223
+ x86_64-linux-gnu
224
+ x86_64-linux-musl
225
+
226
+ DEPENDENCIES
227
+ bundler
228
+ dotenv (~> 2.8)
229
+ minitest
230
+ minitest-profile
231
+ minitest-reporters
232
+ rack-test
233
+ rake (>= 13.0)
234
+ rubocop-bridgetown (~> 0.3)
235
+ toottown!
236
+
237
+ BUNDLED WITH
238
+ 2.6.2
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present Jared White
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # TootTown
2
+
3
+ Bring comments into your [Bridgetown](https://www.bridgetownrb.com) site via Mastodon and the Fediverse!
4
+
5
+ **UNDER DEVELOPMENT**
6
+
7
+ ----
8
+
9
+ ## Installation
10
+
11
+ Run this command to add this plugin to your site's Gemfile:
12
+
13
+ ```shell
14
+ bundle add my_awesome_plugin
15
+ ```
16
+
17
+ Then add the initializer to your configuration in `config/initializers.rb`:
18
+
19
+ ```ruby
20
+ init :my_awesome_plugin
21
+ ```
22
+
23
+ Or if there's a `bridgetown.automation.rb` automation script, you can run that instead for guided setup:
24
+
25
+ ```shell
26
+ bin/bridgetown apply https://github.com/username/my_awesome_plugin
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ The plugin will…
32
+
33
+ ### Optional configuration options
34
+
35
+ The plugin will automatically use any of the following metadata variables if they are present in your site's `_data/site_metadata.yml` file.
36
+
37
+
38
+
39
+ ## Testing
40
+
41
+ * Run `bundle exec rake test` to run the test suite
42
+ * Or run `script/cibuild` to validate with Rubocop and Minitest together.
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it (https://github.com/username/my-awesome-plugin/fork)
47
+ 2. Clone the fork using `git clone` to your local development machine.
48
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 5. Push to the branch (`git push origin my-new-feature`)
51
+ 6. Create a new Pull Request
52
+
53
+ ----
54
+
55
+ ## Releasing (you can delete this section in your own plugin repo)
56
+
57
+ To release a new version of the plugin, simply bump up the version number in both `version.rb` and
58
+ `package.json`, and then run `script/release`. This will require you to have a registered account
59
+ with both the [RubyGems.org](https://rubygems.org) and [NPM](https://www.npmjs.com) registries.
60
+ You can optionally remove the `package.json` and `frontend` folder if you don't need to package frontend
61
+ assets for Webpack.
62
+
63
+ If you run into any problems or need further guidance, please check out our [Bridgetown community resources](https://www.bridgetownrb.com/docs/community)
64
+ where friendly folks are standing by to help you build and release your plugin or theme.
65
+
66
+ **NOTE:** make sure you add the `bridgetown-plugin` [topic](https://github.com/topics/bridgetown-plugin) to your
67
+ plugin's GitHub repo so the plugin or theme will show up on [Bridgetown's official Plugin Directory](https://www.bridgetownrb.com/plugins)! (There may be a day or so delay before you see it appear.)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ t.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,51 @@
1
+ # If your plugin requires a lot of steps to get set up, consider writing an automation to help guide users.
2
+ # You could set up and configure all sorts of things, for example:
3
+ #
4
+ # add_gem("my_plugin")
5
+ #
6
+ # add_yarn_for_gem("my_plugin")
7
+ #
8
+ # add_initializer :"my_plugin" do
9
+ # <<~RUBY
10
+ # do
11
+ # some_config_key 12345
12
+ # end
13
+ # RUBY
14
+ # end
15
+ #
16
+ # create_builder "my_nifty_builder.rb" do
17
+ # <<~RUBY
18
+ # class MyNeatBuilder < SiteBuilder
19
+ # def build
20
+ # puts MyPlugin.hello
21
+ # end
22
+ # end
23
+ # RUBY
24
+ # end
25
+ #
26
+ # javascript_import do
27
+ # <<~JS
28
+ # import { MyPlugin } from "my_plugin"
29
+ # JS
30
+ # end
31
+ #
32
+ # javascript_import 'import "my_plugin/frontend/styles/index.css"'
33
+ #
34
+ # create_file "src/_data/plugin_data.yml" do
35
+ # <<~YAML
36
+ # data:
37
+ # goes: here
38
+ # YAML
39
+ # end
40
+ #
41
+ # color = ask("What's your favorite color?")
42
+ #
43
+ # append_to_file "bridgetown.config.yml" do
44
+ # <<~YAML
45
+ #
46
+ # my_plugin:
47
+ # favorite_color: #{color}
48
+ # YAML
49
+ # end
50
+ #
51
+ # Read the Automations documentation: https://www.bridgetownrb.com/docs/automations
@@ -0,0 +1 @@
1
+ <p>Just use <code>layout: toottown/layout</code> in your page's front matter.</p>
@@ -0,0 +1,17 @@
1
+ # rubocop:disable all
2
+ module Toottown
3
+ class PluginComponent < Bridgetown::Component
4
+ def initialize(hi:)
5
+ @hi = hi
6
+ end
7
+
8
+ # You can remove this and add an ERB, Serbea, etc. template file…or you can
9
+ # use something like Phlex if you're feeling adventurous!
10
+ def template
11
+ <<~HTML
12
+ Well hello there #{hi}!
13
+ HTML
14
+ end
15
+ end
16
+ end
17
+ # rubocop:enable all
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Example Page
4
+ ---
5
+
6
+ If all goes well, this page will be accessible as [`{{ resource.data.relative_url }}`]({{ resource.data.relative_url }}), and you will see a photo of a train:
7
+
8
+ ![Train on Rails]({{ "/toottown/train-on-rails.jpeg" | relative_url }})
@@ -0,0 +1,9 @@
1
+ ---
2
+ layout: default
3
+ ---
4
+
5
+ <p>You can include this layout in your site! 🥳</p>
6
+
7
+ {% render "toottown/layout_help" %}
8
+
9
+ {{ content }}
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Toottown
4
+ class Builder < Bridgetown::Builder
5
+ def build
6
+ liquid_tag "toottown" do
7
+ "This plugin works!"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ :host {
2
+ --comment-margin-block: 2rem;
3
+ --header-gap: 1rem;
4
+ --avatar-size: 3rem;
5
+ --avatar-rounded: 100%;
6
+ --link-color: SlateBlue;
7
+ --header-link-color: var(--link-color);
8
+ --footer-font-size: 80%;
9
+ --paragraph-margin-inline: 0;
10
+ --paragraph-margin-block: 0.75em 1.25em;
11
+
12
+ display: block;
13
+ margin-block: var(--comment-margin-block);
14
+ }
15
+
16
+ a {
17
+ text-decoration: none;
18
+ color: var(--link-color);
19
+ }
20
+
21
+ p {
22
+ margin-inline: var(--paragraph-margin-inline);
23
+ margin-block: var(--paragraph-margin-block);
24
+ }
25
+
26
+ header {
27
+ display: flex;
28
+ align-items: center;
29
+ gap: var(--header-gap);
30
+ }
31
+
32
+ header > a {
33
+ display: contents;
34
+ color: var(--header-link-color);
35
+ }
36
+
37
+ header :is(h4, p) {
38
+ margin: 0;
39
+ }
40
+
41
+ img[part~="avatar"] {
42
+ width: var(--avatar-size);
43
+ height: var(--avatar-size);
44
+ border-radius: var(--avatar-rounded);
45
+ }
46
+
47
+ footer {
48
+ font-size: 85%;
49
+ }
@@ -0,0 +1,59 @@
1
+ require "phlex"
2
+
3
+ module Toottown
4
+ module Models
5
+ class Comment < Phlex::HTML
6
+ register_element :toottown_comment
7
+ register_element :hgroup # FIXME in Phlex! See: https://github.com/joeldrapper/phlex/pull/477
8
+ attr_reader :status
9
+
10
+ def self.styles
11
+ @styles ||= File.read(File.join(__dir__, "comment.css"))
12
+ end
13
+
14
+ def initialize(status:)
15
+ @status = status
16
+ end
17
+
18
+ def content = status.content
19
+
20
+ def account_name = status.account.acct
21
+
22
+ def account_url = status.account.url
23
+
24
+ def display_name = @status.account.display_name
25
+
26
+ def avatar = @status.account.avatar_static
27
+
28
+ def created_at = Bridgetown::Utils.parse_date(@status.created_at).strftime("%B %-d, %Y @ %-I%P →")
29
+
30
+ def url = @status.url
31
+
32
+ def template
33
+ toottown_comment href: url do
34
+ # Shadow DOM:
35
+ template_tag shadowroot: "open", shadowrootmode: "open" do
36
+ header part: "header" do
37
+ a href: account_url, target: "_blank" do
38
+ img part: "avatar", src: avatar
39
+ hgroup do
40
+ h4(part: "display-name") { display_name }
41
+ p(part: "account-name") { "@#{account_name}" }
42
+ end
43
+ end
44
+ end
45
+ unsafe_raw content
46
+ footer part: "footer" do
47
+ a(part: "permalink", href: url, target: "_blank") do
48
+ time(part: "created-at", datetime: @status.created_at) { created_at }
49
+ end
50
+ end
51
+ style do
52
+ unsafe_raw self.class.styles
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,56 @@
1
+ module Toottown
2
+ module Models
3
+ class MastodonConnection
4
+ using Bridgetown::Refinements
5
+
6
+ attr_reader :connection
7
+
8
+ def initialize(instance_url:, access_token:)
9
+ @instance_url, @access_token = instance_url, access_token
10
+
11
+ @connection = Faraday.new(
12
+ instance_url,
13
+ request: { timeout: 5 },
14
+ headers: {"Authorization" => "Bearer #{access_token}"}
15
+ ) { |f| f.response :json }
16
+ end
17
+
18
+ def get(path, **params)
19
+ response = connection.get(path, **params)
20
+ if response.body.is_a?(Array)
21
+ response.body.map(&:as_dots)
22
+ else
23
+ response.body.as_dots
24
+ end
25
+ end
26
+
27
+ def account_id
28
+ @account_id ||= get("/api/v1/accounts/verify_credentials").id
29
+ end
30
+
31
+ def tagged_statuses(tagged)
32
+ get("/api/v1/accounts/#{account_id}/statuses", tagged:, exclude_replies: true, exclude_reblogs: true, limit: 40)
33
+ end
34
+
35
+ def tagged_status_with_link_url(url:, tagged:)
36
+ results = tagged_statuses(tagged)
37
+ results.find { _1.content.include?(url) }
38
+ end
39
+
40
+ def replies_count_of_status(status)
41
+ status.replies_count
42
+ end
43
+
44
+ def replies_of_status(status)
45
+ get("/api/v1/statuses/#{status.id}/context").descendants.map { Toottown::Models::Comment.new(status: _1) }
46
+ end
47
+
48
+ def replies_of_tagged_status_with_link_url(url:, tagged:)
49
+ status = tagged_status_with_link_url(url:, tagged:)
50
+ return unless status
51
+
52
+ [status, replies_of_status(status)]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,56 @@
1
+ module Toottown
2
+ class Routes < Bridgetown::Rack::Routes
3
+ priority :low
4
+
5
+ route do |r|
6
+ r.on "toottown" do
7
+ # NOTE: if you want to wipe out cache easily:
8
+ # $redis.del(*$redis.keys("reply_counts:*"))
9
+ # $redis.del(*$redis.keys("comments:*"))
10
+
11
+ response_cache = ->(key, expire_in:, &block) do
12
+ value = $redis.get(key)
13
+ return value if value
14
+
15
+ value = block.()
16
+ return unless value
17
+
18
+ $redis.set(key, value, ex: expire_in)
19
+
20
+ value
21
+ end
22
+
23
+ limit_url = ->(url) { url[0...128] }
24
+ hashtag = params[:comments_hashtag] || bridgetown_site.config.toottown.comments_hashtag
25
+
26
+ conn = Toottown::Models::MastodonConnection.new(instance_url: bridgetown_site.config.toottown.instance_url, access_token: bridgetown_site.config.toottown.access_token)
27
+
28
+ r.on "comments" do
29
+ next (response.status = 400; "Missing URL Parameter") if params[:url].blank?
30
+
31
+ url = limit_url.(params[:url])
32
+
33
+ r.get "count" do
34
+ count = response_cache.("reply_counts:#{url}", expire_in: bridgetown_site.config.toottown.minutes_to_cache * 60) do
35
+ status = conn.tagged_status_with_link_url(url:, tagged: hashtag)
36
+ status ? conn.replies_count_of_status(status) : nil
37
+ end.to_i
38
+
39
+ { count: }
40
+ end
41
+
42
+ r.get do
43
+ comments = response_cache.("comments:#{url}", expire_in: bridgetown_site.config.toottown.minutes_to_cache * 60) do
44
+ status, replies = conn.replies_of_tagged_status_with_link_url(url:, tagged: hashtag)
45
+ next unless status
46
+
47
+ "<toottown-comments href=\"#{status.url}\">#{replies.map(&:call).join}</toottown-comments>"
48
+ end
49
+
50
+ comments ? comments : ""
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Toottown
4
+ VERSION = "0.2.0"
5
+ end
data/lib/toottown.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "toottown/builder"
5
+
6
+ # @param config [Bridgetown::Configuration::ConfigurationDSL]
7
+ Bridgetown.initializer :toottown do |
8
+ config,
9
+ instance_url: nil,
10
+ access_token: nil,
11
+ minutes_to_cache: 1,
12
+ comments_hashtag: "blog"
13
+ |
14
+ # Add default configuration data:
15
+ config.toottown ||= {}
16
+ config.toottown.instance_url ||= instance_url
17
+ config.toottown.access_token ||= access_token
18
+ config.toottown.minutes_to_cache ||= minutes_to_cache
19
+ config.toottown.comments_hashtag ||= comments_hashtag
20
+
21
+ if instance_url.blank? || access_token.blank?
22
+ Bridgetown.logger.warn "Toottown", "No instance URL or access token provided"
23
+ else
24
+ config.only :server do
25
+ unless defined?($redis)
26
+ require "redis"
27
+ $redis = Redis.new(url: ENV.fetch("REDIS_URL", nil))
28
+ end
29
+
30
+ require "toottown/models/comment"
31
+ require "toottown/models/mastodon_connection"
32
+ require "toottown/routes"
33
+ end
34
+ end
35
+
36
+ # Register your builder:
37
+ config.builder Toottown::Builder
38
+ end
data/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "toottown",
3
+ "version": "0.2.0",
4
+ "main": "frontend/javascript/index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://codeberg.org/jaredwhite/toottown.git"
8
+ },
9
+ "author": "Jared White <jared@whitefusion.studio>",
10
+ "homepage": "https://www.whitefusion.studio",
11
+ "license": "MIT",
12
+ "private": false,
13
+ "files": [
14
+ "frontend"
15
+ ]
16
+ }
data/toottown.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/toottown/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "toottown"
7
+ spec.version = Toottown::VERSION
8
+ spec.author = "Jared White"
9
+ spec.email = "jared@whitefusion.studio"
10
+ spec.summary = "Bring comments into your Bridgetown site via Mastodon and the Fediverse"
11
+ spec.homepage = "https://codeberg.org/jaredwhite/toottown"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
15
+ spec.test_files = spec.files.grep(%r!^test/!)
16
+ spec.require_paths = ["lib"]
17
+ spec.metadata = { "npm_add" => "toottown@#{Toottown::VERSION}" }
18
+
19
+ spec.required_ruby_version = ">= 3.1"
20
+
21
+ spec.add_dependency "bridgetown", ">= 2.0"
22
+ spec.add_dependency "phlex", "~> 1.3"
23
+ spec.add_dependency "redis", "~> 5.0"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake", ">= 13.0"
27
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.3"
28
+ spec.add_development_dependency "dotenv", "~> 2.8"
29
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toottown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jared White
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-10-07 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bridgetown
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: phlex
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ - !ruby/object:Gem::Dependency
41
+ name: redis
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '13.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rubocop-bridgetown
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.3'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.3'
96
+ - !ruby/object:Gem::Dependency
97
+ name: dotenv
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.8'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.8'
110
+ email: jared@whitefusion.studio
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - ".github/workflows/tests.yml"
116
+ - ".gitignore"
117
+ - ".rubocop.yml"
118
+ - CHANGELOG.md
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bridgetown.automation.rb
125
+ - components/toottown/layout_help.liquid
126
+ - components/toottown/plugin_component.rb
127
+ - content/toottown/example_page.md
128
+ - content/toottown/train-on-rails.jpeg
129
+ - layouts/toottown/layout.html
130
+ - lib/toottown.rb
131
+ - lib/toottown/builder.rb
132
+ - lib/toottown/models/comment.css
133
+ - lib/toottown/models/comment.rb
134
+ - lib/toottown/models/mastodon_connection.rb
135
+ - lib/toottown/routes.rb
136
+ - lib/toottown/version.rb
137
+ - package.json
138
+ - toottown.gemspec
139
+ homepage: https://codeberg.org/jaredwhite/toottown
140
+ licenses:
141
+ - MIT
142
+ metadata:
143
+ npm_add: toottown@0.2.0
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '3.1'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubygems_version: 3.6.2
159
+ specification_version: 4
160
+ summary: Bring comments into your Bridgetown site via Mastodon and the Fediverse
161
+ test_files: []