diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 21:22:22 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 21:22:22 -0500 |
commit | 2dea596dbb31f3794744a1bd2c9ec6091d8dfdff (patch) | |
tree | b10639a2cd1f452da72a59503ac16ca8236c5093 | |
parent | 9d8deddb0a9df7d4d7d4b649ddf01b15570719e0 (diff) | |
download | thoughts-2dea596dbb31f3794744a1bd2c9ec6091d8dfdff.tar.gz thoughts-2dea596dbb31f3794744a1bd2c9ec6091d8dfdff.tar.bz2 thoughts-2dea596dbb31f3794744a1bd2c9ec6091d8dfdff.zip |
Send webmentions when publishing/editing a blog post
-rw-r--r-- | app/jobs/send_webmentions_job.rb | 13 | ||||
-rw-r--r-- | app/models/blog.rb | 7 | ||||
-rw-r--r-- | test/jobs/send_webmentions_job_test.rb | 7 |
3 files changed, 27 insertions, 0 deletions
diff --git a/app/jobs/send_webmentions_job.rb b/app/jobs/send_webmentions_job.rb new file mode 100644 index 0000000..359f5b6 --- /dev/null +++ b/app/jobs/send_webmentions_job.rb | |||
@@ -0,0 +1,13 @@ | |||
1 | require 'webmention' | ||
2 | |||
3 | class SendWebmentionsJob < ApplicationJob | ||
4 | queue_as :default | ||
5 | |||
6 | def perform(blog) | ||
7 | source = Rails.application.routes.url_helpers.blog_url(blog, host: "www.fourisland.com") | ||
8 | urls = Webmention.mentioned_urls(source) | ||
9 | urls.each do |url| | ||
10 | Webmention.send_webmention(source, url) | ||
11 | end | ||
12 | end | ||
13 | end | ||
diff --git a/app/models/blog.rb b/app/models/blog.rb index 8599bcd..db05432 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb | |||
@@ -19,6 +19,7 @@ class Blog < ApplicationRecord | |||
19 | 19 | ||
20 | before_validation :set_draft_title | 20 | before_validation :set_draft_title |
21 | before_save :set_published_at | 21 | before_save :set_published_at |
22 | after_save :send_webmentions | ||
22 | 23 | ||
23 | def path | 24 | def path |
24 | "/says/#{slug}" | 25 | "/says/#{slug}" |
@@ -72,4 +73,10 @@ class Blog < ApplicationRecord | |||
72 | self.published_at = nil | 73 | self.published_at = nil |
73 | end | 74 | end |
74 | end | 75 | end |
76 | |||
77 | def send_webmentions | ||
78 | return unless self.published | ||
79 | |||
80 | SendWebmentionsJob.perform_later self | ||
81 | end | ||
75 | end | 82 | end |
diff --git a/test/jobs/send_webmentions_job_test.rb b/test/jobs/send_webmentions_job_test.rb new file mode 100644 index 0000000..72f6ed7 --- /dev/null +++ b/test/jobs/send_webmentions_job_test.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | require "test_helper" | ||
2 | |||
3 | class SendWebmentionsJobTest < ActiveJob::TestCase | ||
4 | # test "the truth" do | ||
5 | # assert true | ||
6 | # end | ||
7 | end | ||