bridgetown-causeway 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5221e6a7518e22b00f2873eeb5cb6212db4974a2f9c873f56b16c88169da31b
4
- data.tar.gz: bda6bae264c4df2615c1a2762072a68f92583a6ef797b13bff0f1199a513ac2f
3
+ metadata.gz: 15bab4a5afe7d4f59f171875afe31104956156a4ffa4e6a09951fd6df5f95d90
4
+ data.tar.gz: e3aef71bc6737cb79e23667660d5495864a721949eb4da215b0d655e6e204832
5
5
  SHA512:
6
- metadata.gz: 1deda3160351e987c852f7791c3928d6ef7a26cb88a980e99a245caa8a8583640fe3329e1a8e4474260568757b8dc4c80df2b2bd5e8f29a040d6536708b8cba2
7
- data.tar.gz: 6c84e84ccffa36efe76fda54b195a769ac4c3dc28ba824eaa5a5a3a7384045357eeaefc8402531d8dd432b9d2230e7d392654c137a78d975a59e0e74135d7e68
6
+ metadata.gz: 4ebd49726a23ab7fd4ed9f93c199afbabed5fba9faa46962d421314db52526a7be53ec890527d903ec0829b482e25a9536109f8f96f94907d0c40b9eeca56193
7
+ data.tar.gz: 999029c2dda8f31847fce82d9772648768c1043354498eafae5d34c5940baa969834f6a2683dee31caf92faa400a33ad217b9a3fcfe1aa5409ddddf0b953a760
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2026-08-24
3
+ ## [0.1.0] - 2026-12-03
4
+
5
+ - Requires causeway 0.2.0. Composing, truncating, and posting now happen in
6
+ causeway (`Causeway.compose` and `Causeway.post`), so every publisher's post is
7
+ truncated to fit, including posts made with `--template`.
8
+ - Breaking: which publishers to post to is set with causeway's `publishers`
9
+ setting. `front_matter_keys` maps each publisher key to the front matter field
10
+ its post id is stored in; Mastodon and Bluesky keep `mastodon_toot_id` and
11
+ `bluesky_post_uri`, and others default to `<key>_post_id`.
12
+ - Breaking: posts without a description now use `default_description`, a
13
+ placeholder to replace in your config, instead of a built-in description.
14
+ - Breaking: `#blog` is no longer added to every post. Set causeway's
15
+ `extra_tags = ["blog"]` to keep it.
16
+
17
+ ## [0.0.1] - 2026-08-24
4
18
 
5
19
  - Initial release
data/README.md CHANGED
@@ -16,7 +16,73 @@ gem install bridgetown-causeway
16
16
 
17
17
  ## Usage
18
18
 
19
- TODO: Write usage instructions here
19
+ Bridgetown::Causeway adds a `bridgetown causeway` command. It publishes a draft post, then cross-posts it to social networks with [Causeway](https://github.com/FASCINATION-works/causeway).
20
+
21
+ ### Configuration
22
+
23
+ Configure both gems in `config/initializers.rb`. Causeway holds the credentials and decides where to post and what the posts look like. See [its README](https://github.com/FASCINATION-works/causeway#usage) for every setting and how to get each network's tokens. Bridgetown::Causeway holds the settings for publishing a post.
24
+
25
+ ```ruby
26
+ Bridgetown.configure do |config|
27
+ require "causeway"
28
+ require "bridgetown/causeway"
29
+
30
+ Causeway.configure do |c|
31
+ c.publishers = %i[mastodon bluesky]
32
+ c.mastodon_token = ENV["MASTODON_TOKEN"]
33
+ c.bluesky_handle = ENV["BLUESKY_HANDLE"]
34
+ c.bluesky_app_password = ENV["BLUESKY_APP_PASSWORD"]
35
+ c.extra_tags = ["blog"] # added to every post
36
+ end
37
+
38
+ Bridgetown::Causeway.configure do |c|
39
+ c.default_description = "New on the blog."
40
+ c.url_generator = ->(path, front_matter) do
41
+ "https://example.com/#{File.basename(path, ".md")}/"
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+ | Setting | Default | Description |
48
+ | --- | --- | --- |
49
+ | `url_generator` | none | A callable that takes the post's path and front matter and returns its public URL. Set it: without it, posts link to `https://example.com/missing-url`. |
50
+ | `default_description` | a placeholder | Used when the post has no `description` in its front matter. The default is a reminder to set it, so replace it. |
51
+ | `summarize_command` | none | A shell command that suggests a description, tags, and categories. See [Summaries](#summaries). |
52
+ | `after_publish` | none | A callable that takes the post's path and front matter. It runs after the post is renamed and marked published, before the commit. |
53
+ | `git_commit` | `true` | Commit and push the published post, and again after the social post IDs are saved. |
54
+ | `front_matter_keys` | `{ mastodon: "mastodon_toot_id", bluesky: "bluesky_post_uri" }` | The front matter field each network's post ID is saved in. Networks not listed use `<key>_post_id`, such as `linkedin_post_id`. |
55
+
56
+ Secrets can be callables, such as `` -> { `op read "op://..."`.strip } ``. Causeway calls them only when it posts, so builds and server boots never ask for them.
57
+
58
+ ### Publishing a post
59
+
60
+ ```bash
61
+ bin/bridgetown causeway src/_posts/my-post.md
62
+ ```
63
+
64
+ For a post that isn't published yet, the command:
65
+
66
+ 1. Runs `summarize_command`, if set, and asks you to choose and edit a description, tags, and categories.
67
+ 2. Asks you to type `publish` to confirm.
68
+ 3. Sets `date` to now, sets `published: true`, and renames the file to start with today's date.
69
+ 4. Runs `after_publish`, then commits and pushes (when `git_commit` is on).
70
+ 5. Waits for you to press Enter once the site is live.
71
+ 6. Posts to each of Causeway's `publishers`, saves each post's ID in the front matter, then commits and pushes again.
72
+
73
+ The post text comes from Causeway's `template`. `{description}` is the post's `description`, or `default_description` if it has none. `{url}` comes from `url_generator`. `{tags}` comes from the post's `tags` plus Causeway's `extra_tags`. Use `--template` to post different text once, for example `--template "Updated: {url}"`. Causeway shortens the text to fit each network's length limit.
74
+
75
+ If a network fails, the command lists it and exits with an error. Fix the problem and run the command again. For a post that is already published, it skips straight to posting, and only posts to networks with no post ID in the front matter.
76
+
77
+ ### Summaries
78
+
79
+ `summarize_command` is run three times, with `%{path}` replaced by the post's path. Each run should print JSON like this, optionally after a `Summarizing...` line:
80
+
81
+ ```json
82
+ { "result": { "summary": "A description.", "tags": ["ruby", "bridgetown"], "concepts": "ruby, static sites" } }
83
+ ```
84
+
85
+ You choose one suggestion for each of `description`, `tags`, and `preview_text` (from `concepts`, capitalized), edit it, and it is saved to the front matter.
20
86
 
21
87
  ## Development
22
88
 
@@ -24,9 +24,7 @@ module Bridgetown
24
24
  def call # rubocop:disable Metrics
25
25
  path = post_path
26
26
 
27
- unless File.exist?(path)
28
- abort "No post found at #{path}"
29
- end
27
+ abort "No post found at #{path}" unless File.exist?(path)
30
28
 
31
29
  config = configuration_with_overrides(options, Bridgetown::Current.preloaded_configuration)
32
30
  config.run_initializers! context: :static
@@ -68,7 +66,7 @@ module Bridgetown
68
66
  end
69
67
  content = update_front_matter_field(content, "tags", edited_tags.strip) if edited_tags
70
68
  if edited_categories
71
- capitalized_cats = edited_categories.split(',').map(&:strip).map(&:capitalize).join(', ')
69
+ capitalized_cats = edited_categories.split(",").map(&:strip).map(&:capitalize).join(", ")
72
70
  content = update_front_matter_field(content, "preview_text", capitalized_cats)
73
71
  end
74
72
 
@@ -85,14 +83,10 @@ module Bridgetown
85
83
  if already_published
86
84
  url = generate_url(path, front_matter)
87
85
  # 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?
86
+ pending = ::Causeway.publishers.reject { |publisher| posted?(front_matter, publisher.key) }
91
87
 
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(', ')}"
88
+ abort "Post is already fully published to all networks: #{path}" if pending.empty?
89
+ puts "Post already published. Resuming social posts for: #{pending.map(&:name).join(", ")}"
96
90
  else
97
91
  # Rename and update date
98
92
  old_path = path
@@ -100,20 +94,20 @@ module Bridgetown
100
94
  new_date_str = now.strftime("%Y-%m-%d %H:%M:%S %z")
101
95
  new_prefix = now.strftime("%Y-%m-%d")
102
96
 
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
97
+ content = if content =~ /^date:.*$/
98
+ content.sub(/^date:.*$/, "date: #{new_date_str}")
99
+ else
100
+ update_front_matter_field(content, "date", new_date_str)
101
+ end
108
102
 
109
103
  content = update_front_matter_field(content, "published", "true")
110
104
 
111
105
  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
106
+ new_basename = if basename.match?(/^\d{4}-\d{2}-\d{2}-/)
107
+ basename.sub(/^\d{4}-\d{2}-\d{2}-/, "#{new_prefix}-")
108
+ else
109
+ "#{new_prefix}-#{basename}"
110
+ end
117
111
 
118
112
  new_path = File.join(File.dirname(path), new_basename)
119
113
 
@@ -148,59 +142,28 @@ module Bridgetown
148
142
  end
149
143
 
150
144
  # 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
145
+ text = ::Causeway.compose(
146
+ description: front_matter["description"] || Bridgetown::Causeway.configuration.default_description,
147
+ url: url,
148
+ tags: front_matter["tags"] || "",
149
+ template: options[:template] || ::Causeway.configuration.template
150
+ )
154
151
 
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---"
152
+ puts "Base social post text (#{text.length} chars):\n---\n#{text}\n---"
162
153
 
163
- publishers = [
164
- [::Causeway::Publishers::Mastodon.new, "mastodon_toot_id"],
165
- [::Causeway::Publishers::Bluesky.new, "bluesky_post_uri"]
166
- ]
154
+ posted_keys = ::Causeway.publishers.map(&:key).select { |key| posted?(front_matter, key) }
155
+ posted_keys.each { |key| puts "#{key}: already posted (#{front_matter[front_matter_key(key)]}), skipping." }
167
156
 
168
157
  posted = []
169
158
  errors = []
170
159
 
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
-
160
+ ::Causeway.post(text, skip: posted_keys) do |publisher, result|
195
161
  if result[:error]
196
- puts "FAILED"
197
- puts " #{result[:error]}"
162
+ puts "#{publisher.name}: FAILED\n #{result[:error]}"
198
163
  errors << publisher.name
199
164
  else
200
- puts "OK"
201
- puts " #{result[:url]}"
202
- content = update_front_matter_field(content, fm_key, result[:id])
203
- File.write(path, content)
165
+ puts "#{publisher.name}: OK\n #{result[:url]}"
166
+ File.write(path, update_front_matter_field(File.read(path), front_matter_key(publisher.key), result[:id]))
204
167
  posted << publisher.name
205
168
  end
206
169
  end
@@ -209,11 +172,11 @@ module Bridgetown
209
172
  git("add", path)
210
173
  git("commit", "-m", "Add social post IDs to #{File.basename(path)}")
211
174
  git("push")
212
- puts "\nCommitted and pushed social post IDs (#{posted.join(', ')})."
175
+ puts "\nCommitted and pushed social post IDs (#{posted.join(", ")})."
213
176
  end
214
177
 
215
178
  if errors.any?
216
- puts "\nFailed to post to: #{errors.join(', ')}"
179
+ puts "\nFailed to post to: #{errors.join(", ")}"
217
180
  puts "Fix the issue and re-run to resume."
218
181
  exit 1
219
182
  end
@@ -223,6 +186,14 @@ module Bridgetown
223
186
 
224
187
  private
225
188
 
189
+ def front_matter_key(publisher_key)
190
+ Bridgetown::Causeway.configuration.front_matter_key(publisher_key)
191
+ end
192
+
193
+ def posted?(front_matter, publisher_key)
194
+ !front_matter[front_matter_key(publisher_key)].to_s.empty?
195
+ end
196
+
226
197
  # Values are deliberately kept as strings: YAML would coerce `date:` into a
227
198
  # Time, which breaks url_generator callbacks that expect to `Date.parse` it.
228
199
  def parse_front_matter(content)
@@ -244,14 +215,14 @@ module Bridgetown
244
215
 
245
216
  def update_front_matter_field(content, field, value)
246
217
  if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
247
- front_matter = $1
248
- body = $' || ""
218
+ front_matter = ::Regexp.last_match(1)
219
+ body = ::Regexp.last_match.post_match || ""
249
220
 
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
221
+ front_matter = if front_matter.match?(/^#{field}:/)
222
+ front_matter.sub(/^#{field}:.*$/, "#{field}: #{value}")
223
+ else
224
+ front_matter + "#{field}: #{value}\n"
225
+ end
255
226
 
256
227
  "#{front_matter}---\n#{body}"
257
228
  else
@@ -269,7 +240,7 @@ module Bridgetown
269
240
 
270
241
  def git(*args, allow_failure: false)
271
242
  success = system("git", *args)
272
- abort "Git command failed: git #{args.join(' ')}" if !success && !allow_failure
243
+ abort "Git command failed: git #{args.join(" ")}" if !success && !allow_failure
273
244
  end
274
245
 
275
246
  def pick_field(label, values)
@@ -281,12 +252,13 @@ module Bridgetown
281
252
  print "Choose (1-#{deduped.size}, or 0 to skip): "
282
253
  num = $stdin.gets.strip.to_i
283
254
  return nil if num == 0
284
- chosen = (num > 0 && num <= deduped.size) ? deduped[num - 1] : deduped[0]
255
+
256
+ chosen = num > 0 && num <= deduped.size ? deduped[num - 1] : deduped[0]
285
257
  ask_with_default("Edit: ", chosen)
286
258
  end
287
259
 
288
260
  def ask_with_default(prompt, default)
289
- Reline.pre_input_hook = -> {
261
+ Reline.pre_input_hook = lambda {
290
262
  Reline.insert_text(default || "")
291
263
  Reline.redisplay
292
264
  Reline.pre_input_hook = nil
@@ -1,13 +1,24 @@
1
1
  module Bridgetown
2
2
  module Causeway
3
3
  class Configuration
4
- attr_accessor :summarize_command
5
- attr_accessor :url_generator
6
- attr_accessor :after_publish
7
- attr_accessor :git_commit
4
+ attr_accessor :summarize_command, :url_generator, :after_publish, :git_commit
5
+
6
+ # Used when a post has no description in its front matter.
7
+ attr_accessor :default_description
8
+
9
+ # The front matter field each publisher's post id is stored in, by
10
+ # publisher key. Publishers not listed use "<key>_post_id". Which
11
+ # publishers to post to is set with Causeway's `publishers`.
12
+ attr_accessor :front_matter_keys
8
13
 
9
14
  def initialize
10
15
  @git_commit = true
16
+ @default_description = "Set default_description in your Bridgetown::Causeway config."
17
+ @front_matter_keys = { mastodon: "mastodon_toot_id", bluesky: "bluesky_post_uri" }
18
+ end
19
+
20
+ def front_matter_key(publisher_key)
21
+ front_matter_keys.fetch(publisher_key, "#{publisher_key}_post_id")
11
22
  end
12
23
  end
13
24
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Causeway
5
- VERSION = "0.0.1"
5
+ VERSION = "0.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-causeway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Heiligers
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: 0.2.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: reline
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 4.0.16
96
+ rubygems_version: 4.0.20
97
97
  specification_version: 4
98
98
  summary: Bridgetown plugin for Causeway.
99
99
  test_files: []