bridgetown-causeway 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5221e6a7518e22b00f2873eeb5cb6212db4974a2f9c873f56b16c88169da31b
4
+ data.tar.gz: bda6bae264c4df2615c1a2762072a68f92583a6ef797b13bff0f1199a513ac2f
5
+ SHA512:
6
+ metadata.gz: 1deda3160351e987c852f7791c3928d6ef7a26cb88a980e99a245caa8a8583640fe3329e1a8e4474260568757b8dc4c80df2b2bd5e8f29a040d6536708b8cba2
7
+ data.tar.gz: 6c84e84ccffa36efe76fda54b195a769ac4c3dc28ba824eaa5a5a3a7384045357eeaefc8402531d8dd432b9d2230e7d392654c137a78d975a59e0e74135d7e68
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-08-24
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "bridgetown-causeway" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["marc@eternal.co.za"](mailto:"marc@eternal.co.za").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Marc Heiligers
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Bridgetown::Causeway
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ ```bash
8
+ bundle add bridgetown-causeway
9
+ ```
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ ```bash
14
+ gem install bridgetown-causeway
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/FASCINATION-works/bridgetown-causeway. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/FASCINATION-works/bridgetown-causeway/blob/main/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Bridgetown::Causeway project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/FASCINATION-works/bridgetown-causeway/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,298 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "bridgetown-core/commands/concerns/configuration_overridable"
5
+ require "json"
6
+ require "reline"
7
+ require "shellwords"
8
+
9
+ module Bridgetown
10
+ module Causeway
11
+ class Command < Bridgetown::Command
12
+ include Bridgetown::Commands::ConfigurationOverridable
13
+
14
+ self.description = "Publish a Bridgetown post and cross-post it via Causeway"
15
+
16
+ one :post_path, "Path to the post to publish", required: true
17
+
18
+ options do
19
+ Bridgetown::Commands::ConfigurationOverridable.include_options(self)
20
+ option "-t/--template <TEXT>",
21
+ "Social post template ({url} is replaced with the post URL)"
22
+ end
23
+
24
+ def call # rubocop:disable Metrics
25
+ path = post_path
26
+
27
+ unless File.exist?(path)
28
+ abort "No post found at #{path}"
29
+ end
30
+
31
+ config = configuration_with_overrides(options, Bridgetown::Current.preloaded_configuration)
32
+ config.run_initializers! context: :static
33
+
34
+ content = File.read(path)
35
+ front_matter, _body = parse_front_matter(content)
36
+
37
+ already_published = front_matter["published"] == "true"
38
+
39
+ unless already_published
40
+ # Ask for summaries if summarize_command is present
41
+ cmd = Bridgetown::Causeway.configuration.summarize_command
42
+ if cmd
43
+ summaries = []
44
+ 3.times do |i|
45
+ puts "Running summary #{i + 1}/3..."
46
+ eval_cmd = cmd.gsub("%{path}", path.shellescape)
47
+ output = `#{eval_cmd} 2>/dev/null`
48
+ begin
49
+ summaries << JSON.parse(output.split("Summarizing...").last)["result"]
50
+ rescue StandardError => e
51
+ puts "Failed to parse summary output: #{e.message}"
52
+ end
53
+ end
54
+
55
+ # Prompt to choose
56
+ if summaries.any?
57
+ desc_values = summaries.map { |s| s["summary"] }
58
+ tag_values = summaries.map { |s| s["tags"]&.join(" ") }
59
+ concept_values = summaries.map { |s| s["concepts"] }
60
+
61
+ edited_summary = pick_field("Description", desc_values)
62
+ edited_tags = pick_field("Tags", tag_values)
63
+ edited_categories = pick_field("Categories", concept_values)
64
+
65
+ if edited_summary
66
+ safe_summary = edited_summary.strip.gsub('"', '\\"')
67
+ content = update_front_matter_field(content, "description", %("#{safe_summary}"))
68
+ end
69
+ content = update_front_matter_field(content, "tags", edited_tags.strip) if edited_tags
70
+ if edited_categories
71
+ capitalized_cats = edited_categories.split(',').map(&:strip).map(&:capitalize).join(', ')
72
+ content = update_front_matter_field(content, "preview_text", capitalized_cats)
73
+ end
74
+
75
+ File.write(path, content)
76
+ front_matter, _body = parse_front_matter(content)
77
+ end
78
+ end
79
+
80
+ print "\nType 'publish' to confirm publishing: "
81
+ confirmation = $stdin.gets.strip
82
+ abort "Publishing aborted." unless confirmation.downcase == "publish"
83
+ end
84
+
85
+ if already_published
86
+ url = generate_url(path, front_matter)
87
+ # check pending
88
+ pending = []
89
+ pending << ::Causeway::Publishers::Mastodon.new if front_matter["mastodon_toot_id"].nil? || front_matter["mastodon_toot_id"].to_s.empty?
90
+ pending << ::Causeway::Publishers::Bluesky.new if front_matter["bluesky_post_uri"].nil? || front_matter["bluesky_post_uri"].to_s.empty?
91
+
92
+ if pending.empty?
93
+ abort "Post is already fully published to all networks: #{path}"
94
+ end
95
+ puts "Post already published. Resuming social posts for: #{pending.map(&:name).join(', ')}"
96
+ else
97
+ # Rename and update date
98
+ old_path = path
99
+ now = Time.now
100
+ new_date_str = now.strftime("%Y-%m-%d %H:%M:%S %z")
101
+ new_prefix = now.strftime("%Y-%m-%d")
102
+
103
+ if content =~ /^date:.*$/
104
+ content = content.sub(/^date:.*$/, "date: #{new_date_str}")
105
+ else
106
+ content = update_front_matter_field(content, "date", new_date_str)
107
+ end
108
+
109
+ content = update_front_matter_field(content, "published", "true")
110
+
111
+ basename = File.basename(path)
112
+ if basename.match?(/^\d{4}-\d{2}-\d{2}-/)
113
+ new_basename = basename.sub(/^\d{4}-\d{2}-\d{2}-/, "#{new_prefix}-")
114
+ else
115
+ new_basename = "#{new_prefix}-#{basename}"
116
+ end
117
+
118
+ new_path = File.join(File.dirname(path), new_basename)
119
+
120
+ if old_path != new_path
121
+ File.write(old_path, content)
122
+ File.rename(old_path, new_path)
123
+ path = new_path
124
+ git("rm", "--cached", old_path, allow_failure: true) if Bridgetown::Causeway.configuration.git_commit
125
+ git("add", path) if Bridgetown::Causeway.configuration.git_commit
126
+ else
127
+ File.write(path, content)
128
+ git("add", path) if Bridgetown::Causeway.configuration.git_commit
129
+ end
130
+
131
+ # Re-parse front matter
132
+ front_matter, _body = parse_front_matter(content)
133
+ url = generate_url(path, front_matter)
134
+
135
+ if Bridgetown::Causeway.configuration.after_publish
136
+ Bridgetown::Causeway.configuration.after_publish.call(path, front_matter)
137
+ end
138
+
139
+ if Bridgetown::Causeway.configuration.git_commit
140
+ git("commit", "-m", "Publish #{File.basename(path)}")
141
+ git("push")
142
+ puts "Committed and pushed."
143
+ end
144
+
145
+ puts "\nWaiting for deployment..."
146
+ print "Press Enter when the site is live: "
147
+ $stdin.gets
148
+ end
149
+
150
+ # Post to networks
151
+ description = front_matter["description"] || "A handful of things that caught my attention."
152
+ tags = (front_matter["tags"] || "").split(/\s+/).reject(&:empty?).map { |t| "##{t}" }.join(" ")
153
+ suffix = "\n\n#{url}\n\n#{tags} #blog".rstrip
154
+
155
+ if options[:template]
156
+ base_text = options[:template].gsub("{url}", url)
157
+ else
158
+ base_text = "#{description}#{suffix}"
159
+ end
160
+
161
+ puts "Base social post text (#{base_text.length} chars):\n---\n#{base_text}\n---"
162
+
163
+ publishers = [
164
+ [::Causeway::Publishers::Mastodon.new, "mastodon_toot_id"],
165
+ [::Causeway::Publishers::Bluesky.new, "bluesky_post_uri"]
166
+ ]
167
+
168
+ posted = []
169
+ errors = []
170
+
171
+ publishers.each do |pub_entry|
172
+ publisher, fm_key = pub_entry
173
+ content = File.read(path)
174
+ front_matter, _ = parse_front_matter(content)
175
+
176
+ existing = front_matter[fm_key]
177
+ if existing && !existing.to_s.empty?
178
+ puts "#{publisher.name}: already posted (#{existing}), skipping."
179
+ next
180
+ end
181
+
182
+ publisher_text = base_text
183
+ if !options[:template] && publisher.name == "Bluesky"
184
+ max_desc_len = 300 - suffix.grapheme_clusters.size
185
+ if description.grapheme_clusters.size > max_desc_len
186
+ puts "\nWarning: Description is too long for Bluesky (#{description.grapheme_clusters.size} graphemes). Truncating."
187
+ truncated_desc = description.grapheme_clusters[0...(max_desc_len - 3)].join.strip + "..."
188
+ publisher_text = "#{truncated_desc}#{suffix}"
189
+ end
190
+ end
191
+
192
+ print "Posting to #{publisher.name}... "
193
+ result = publisher.post(publisher_text)
194
+
195
+ if result[:error]
196
+ puts "FAILED"
197
+ puts " #{result[:error]}"
198
+ errors << publisher.name
199
+ else
200
+ puts "OK"
201
+ puts " #{result[:url]}"
202
+ content = update_front_matter_field(content, fm_key, result[:id])
203
+ File.write(path, content)
204
+ posted << publisher.name
205
+ end
206
+ end
207
+
208
+ if posted.any? && Bridgetown::Causeway.configuration.git_commit
209
+ git("add", path)
210
+ git("commit", "-m", "Add social post IDs to #{File.basename(path)}")
211
+ git("push")
212
+ puts "\nCommitted and pushed social post IDs (#{posted.join(', ')})."
213
+ end
214
+
215
+ if errors.any?
216
+ puts "\nFailed to post to: #{errors.join(', ')}"
217
+ puts "Fix the issue and re-run to resume."
218
+ exit 1
219
+ end
220
+
221
+ puts "\nDone!"
222
+ end
223
+
224
+ private
225
+
226
+ # Values are deliberately kept as strings: YAML would coerce `date:` into a
227
+ # Time, which breaks url_generator callbacks that expect to `Date.parse` it.
228
+ def parse_front_matter(content)
229
+ match = content.match(/\A---\n(.*?\n)---\n(.*)\z/m)
230
+ abort "Invalid front matter" unless match
231
+
232
+ front_matter = {}
233
+ match[1].each_line do |line|
234
+ next unless line =~ /\A(\w[\w_]*):\s*(.*)\s*\z/
235
+
236
+ key = Regexp.last_match(1)
237
+ value = Regexp.last_match(2).strip
238
+ value = value[1..-2] if value.start_with?('"') && value.end_with?('"')
239
+ front_matter[key] = value
240
+ end
241
+
242
+ [front_matter, match[2]]
243
+ end
244
+
245
+ def update_front_matter_field(content, field, value)
246
+ if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
247
+ front_matter = $1
248
+ body = $' || ""
249
+
250
+ if front_matter.match?(/^#{field}:/)
251
+ front_matter = front_matter.sub(/^#{field}:.*$/, "#{field}: #{value}")
252
+ else
253
+ front_matter = front_matter + "#{field}: #{value}\n"
254
+ end
255
+
256
+ "#{front_matter}---\n#{body}"
257
+ else
258
+ "---\n#{field}: #{value}\n---\n#{content}"
259
+ end
260
+ end
261
+
262
+ def generate_url(path, front_matter)
263
+ if Bridgetown::Causeway.configuration.url_generator
264
+ Bridgetown::Causeway.configuration.url_generator.call(path, front_matter)
265
+ else
266
+ "https://example.com/missing-url"
267
+ end
268
+ end
269
+
270
+ def git(*args, allow_failure: false)
271
+ success = system("git", *args)
272
+ abort "Git command failed: git #{args.join(' ')}" if !success && !allow_failure
273
+ end
274
+
275
+ def pick_field(label, values)
276
+ deduped = values.compact.uniq
277
+ puts "\n#{label}:"
278
+ deduped.each_with_index do |v, i|
279
+ puts " [#{i + 1}] #{v}"
280
+ end
281
+ print "Choose (1-#{deduped.size}, or 0 to skip): "
282
+ num = $stdin.gets.strip.to_i
283
+ return nil if num == 0
284
+ chosen = (num > 0 && num <= deduped.size) ? deduped[num - 1] : deduped[0]
285
+ ask_with_default("Edit: ", chosen)
286
+ end
287
+
288
+ def ask_with_default(prompt, default)
289
+ Reline.pre_input_hook = -> {
290
+ Reline.insert_text(default || "")
291
+ Reline.redisplay
292
+ Reline.pre_input_hook = nil
293
+ }
294
+ Reline.readline(prompt, false)
295
+ end
296
+ end
297
+ end
298
+ end
@@ -0,0 +1,24 @@
1
+ module Bridgetown
2
+ module Causeway
3
+ class Configuration
4
+ attr_accessor :summarize_command
5
+ attr_accessor :url_generator
6
+ attr_accessor :after_publish
7
+ attr_accessor :git_commit
8
+
9
+ def initialize
10
+ @git_commit = true
11
+ end
12
+ end
13
+
14
+ class << self
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Causeway
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "causeway"
5
+ require_relative "causeway/version"
6
+ require_relative "causeway/configuration"
7
+ require_relative "causeway/command"
8
+
9
+ module Bridgetown
10
+ module Causeway
11
+ class Error < StandardError; end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Loaded by Bridgetown's PluginManager at CLI boot (via the `bridgetown_features`
4
+ # gemspec metadata). Registration is deferred so the command file is only required
5
+ # once `bridgetown-core/commands/application` is on the stack.
6
+ Bridgetown::Commands::Registrations.register do
7
+ require "bridgetown/causeway"
8
+
9
+ register Bridgetown::Causeway::Command, :causeway
10
+ end
@@ -0,0 +1,6 @@
1
+ module Bridgetown
2
+ module Causeway
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown-causeway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marc Heiligers
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 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: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: causeway
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: reline
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ description: Publish Bridgetown posts to social media using Causeway.
55
+ email:
56
+ - rubygems@heiligers.us
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - CODE_OF_CONDUCT.md
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/bridgetown/causeway.rb
67
+ - lib/bridgetown/causeway/command.rb
68
+ - lib/bridgetown/causeway/configuration.rb
69
+ - lib/bridgetown/causeway/version.rb
70
+ - lib/bridgetown/features/bridgetown-causeway.rb
71
+ - sig/bridgetown/causeway.rbs
72
+ homepage: https://github.com/FASCINATION-works/bridgetown-causeway
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ allowed_push_host: https://rubygems.org
77
+ homepage_uri: https://github.com/FASCINATION-works/bridgetown-causeway
78
+ bridgetown_features: 'true'
79
+ source_code_uri: https://github.com/FASCINATION-works/bridgetown-causeway
80
+ changelog_uri: https://github.com/FASCINATION-works/bridgetown-causeway/blob/main/CHANGELOG.md
81
+ rubygems_mfa_required: 'true'
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.2.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 4.0.16
97
+ specification_version: 4
98
+ summary: Bridgetown plugin for Causeway.
99
+ test_files: []