First pass at webmentions
This commit is contained in:
37
app/actions/webmentions/create.rb
Normal file
37
app/actions/webmentions/create.rb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Adamantium
|
||||||
|
module Actions
|
||||||
|
module Webmentions
|
||||||
|
class Create < Adamantium::Action
|
||||||
|
|
||||||
|
include Deps["repos.webmentions_repo", "repos.post_repo"]
|
||||||
|
|
||||||
|
def handle(req, res)
|
||||||
|
req.params[:children].each do |child|
|
||||||
|
if child[:"wm-property"] == "in-reply-to"
|
||||||
|
|
||||||
|
slug = child[:"in-reply-to"].split("/").last
|
||||||
|
post = post_repo.fetch!(slug)
|
||||||
|
|
||||||
|
attrs = {
|
||||||
|
type: "reply",
|
||||||
|
author_name: child[:author][:name],
|
||||||
|
author_photo: child[:author][:photo],
|
||||||
|
author_url: child[:author][:url],
|
||||||
|
published_at: child[:published],
|
||||||
|
content_html: child[:content][:html],
|
||||||
|
content_text: child[:content][:text],
|
||||||
|
source_url: child[:url],
|
||||||
|
target_url: child[:"in-reply-to"],
|
||||||
|
post_id: post.id
|
||||||
|
}
|
||||||
|
|
||||||
|
webmentions_repo.create(attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -216,7 +216,7 @@ module Adamantium
|
|||||||
def fetch!(slug)
|
def fetch!(slug)
|
||||||
posts
|
posts
|
||||||
.published
|
.published
|
||||||
.combine(:tags, :trips)
|
.combine(:tags, :trips, :webmentions)
|
||||||
.where(slug: slug)
|
.where(slug: slug)
|
||||||
.one!
|
.one!
|
||||||
end
|
end
|
||||||
|
7
app/repos/webmentions_repo.rb
Normal file
7
app/repos/webmentions_repo.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module Adamantium
|
||||||
|
module Repos
|
||||||
|
class WebmentionsRepo < Adamantium::Repo[:webmentions]
|
||||||
|
commands :create
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -41,6 +41,20 @@ article class="h-entry"
|
|||||||
|
|
||||||
- if post.location
|
- if post.location
|
||||||
img class="shadow-solid shadow-pink-100 dark:shadow-pink-200 rounded mb-4" src=post.large_map
|
img class="shadow-solid shadow-pink-100 dark:shadow-pink-200 rounded mb-4" src=post.large_map
|
||||||
|
-if post.webmentions && post.webmentions.count > 0
|
||||||
|
div class="mt-12"
|
||||||
|
h3 #{post.webmentions.count} Comment(s)
|
||||||
|
- post.webmentions.each do |mention|
|
||||||
|
div class="prose-p:m-1"
|
||||||
|
div class="flex h-6"
|
||||||
|
img class="w-6 m-0 mr-2" src=mention.author_photo
|
||||||
|
a class="block" href=mention.author_url
|
||||||
|
= mention.author_name
|
||||||
|
div
|
||||||
|
== mention.content_html
|
||||||
|
div class="text-sm"
|
||||||
|
a href=mention.source_url
|
||||||
|
= mention.published_at.strftime("%e %B, %Y")
|
||||||
div class="mb-12"
|
div class="mb-12"
|
||||||
- if trip
|
- if trip
|
||||||
div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex gap-4"
|
div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex gap-4"
|
||||||
|
@@ -19,6 +19,8 @@ module Adamantium
|
|||||||
post "/", to: "posts.handle"
|
post "/", to: "posts.handle"
|
||||||
post "/media", to: "media.create"
|
post "/media", to: "media.create"
|
||||||
get "/media", to: "media.show"
|
get "/media", to: "media.show"
|
||||||
|
|
||||||
|
post "/webmentions", to: "webmentions.create"
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/", to: "site.home"
|
get "/", to: "site.home"
|
||||||
|
24
db/migrate/20230704111528_create_webmentions.rb
Normal file
24
db/migrate/20230704111528_create_webmentions.rb
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
ROM::SQL.migration do
|
||||||
|
change do
|
||||||
|
create_table :webmentions do
|
||||||
|
primary_key :id
|
||||||
|
column :type, :text, null: false, default: ""
|
||||||
|
|
||||||
|
column :author_name, :text, null: false, default: ""
|
||||||
|
column :author_photo, :text, null: false, default: ""
|
||||||
|
column :author_url, :text, default: ""
|
||||||
|
|
||||||
|
column :published_at, :timestamp
|
||||||
|
|
||||||
|
column :content_html, :text, null: false, default: ""
|
||||||
|
column :content_text, :text, null: false, default: ""
|
||||||
|
|
||||||
|
column :source_url, :text, null: false, default: ""
|
||||||
|
column :target_url, :text, null: false, default: ""
|
||||||
|
|
||||||
|
foreign_key :post_id, :posts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -11,6 +11,8 @@ module Adamantium
|
|||||||
|
|
||||||
has_many :post_trips
|
has_many :post_trips
|
||||||
has_many :trips, through: :post_trips
|
has_many :trips, through: :post_trips
|
||||||
|
|
||||||
|
has_many :webmentions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
21
lib/adamantium/persistence/relations/webmentions.rb
Normal file
21
lib/adamantium/persistence/relations/webmentions.rb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Adamantium
|
||||||
|
module Persistence
|
||||||
|
module Relations
|
||||||
|
class Webmentions < ROM::Relation[:sql]
|
||||||
|
schema :webmentions, infer: true do
|
||||||
|
associations do
|
||||||
|
belongs_to :post
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
auto_struct(true)
|
||||||
|
|
||||||
|
def published
|
||||||
|
where(self[:published_at] <= Time.now)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user