Add management of webmentions
This commit is contained in:
@@ -96,7 +96,7 @@ module Adamantium
|
||||
.published
|
||||
.combine(:tags, :webmentions)
|
||||
.node(:webmentions) { |webmention|
|
||||
webmention.where(type: "reply")
|
||||
webmention.published.where(type: "reply")
|
||||
}
|
||||
.order(Sequel.desc(:published_at))
|
||||
.limit(limit)
|
||||
@@ -186,7 +186,7 @@ module Adamantium
|
||||
.published
|
||||
.combine(:tags, :trips, :webmentions)
|
||||
.node(:webmentions) { |webmention|
|
||||
webmention.where(type: "reply")
|
||||
webmention.published.where(type: "reply")
|
||||
}
|
||||
.where(slug: slug)
|
||||
.one!
|
||||
|
@@ -20,7 +20,7 @@ end
|
||||
|
||||
require "adamantium/middleware/header_fix"
|
||||
use Adamantium::Middleware::HeaderFix do |headers, env|
|
||||
unless headers["Content-Type"].include? "xml"
|
||||
unless headers["Content-Type"]&.include? "xml"
|
||||
headers["Content-Type"] = "text/html; charset=utf-8"
|
||||
end
|
||||
end
|
||||
|
12
slices/admin/actions/webmentions/index.rb
Normal file
12
slices/admin/actions/webmentions/index.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Actions
|
||||
module Webmentions
|
||||
class Index < Admin::Action
|
||||
def handle(request, response)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
slices/admin/actions/webmentions/update.rb
Normal file
25
slices/admin/actions/webmentions/update.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Actions
|
||||
module Webmentions
|
||||
class Update < Admin::Action
|
||||
include Deps["repos.webmention_repo"]
|
||||
|
||||
def handle(req, resp)
|
||||
update_type = req.params[:update_type]
|
||||
if update_type == "archive"
|
||||
webmention_repo.update(req.params[:id], published_at: nil)
|
||||
end
|
||||
|
||||
if update_type == "publish"
|
||||
webmention_repo.update(req.params[:id], published_at: Time.now)
|
||||
end
|
||||
|
||||
resp.headers["HX-Refresh"] = true
|
||||
resp.status = 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -68,5 +68,8 @@ module Admin
|
||||
get "/books", to: Auth.call(action: "books.index")
|
||||
patch "/books/:id", to: Auth.call(action: "books.update")
|
||||
post "/books", to: Auth.call(action: "books.create")
|
||||
|
||||
get "/webmentions", to: Auth.call(action: "webmentions.index")
|
||||
patch "/webmentions/:id/:update_type", to: Auth.call(action: "webmentions.update")
|
||||
end
|
||||
end
|
||||
|
13
slices/admin/repos/webmention_repo.rb
Normal file
13
slices/admin/repos/webmention_repo.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Admin
|
||||
module Repos
|
||||
class WebmentionRepo < Adamantium::Repo[:webmentions]
|
||||
commands update: :by_pk
|
||||
|
||||
def list_all
|
||||
webmentions
|
||||
.order(:id)
|
||||
.to_a
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -21,6 +21,8 @@ div class="max-w-prose mx-auto prose dark:prose-invert"
|
||||
a href="/admin/bookmarks" Bookmarks
|
||||
li
|
||||
a href="/admin/trips" Trips
|
||||
li
|
||||
a href="/admin/webmentions" Webmentions
|
||||
li
|
||||
a href="/admin/apple_music" Apple Music
|
||||
|
||||
|
36
slices/admin/templates/webmentions/index.html.slim
Normal file
36
slices/admin/templates/webmentions/index.html.slim
Normal file
@@ -0,0 +1,36 @@
|
||||
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
|
||||
h1 Admin // Webmentions
|
||||
|
||||
table
|
||||
tr
|
||||
td ID
|
||||
td Author
|
||||
td Content
|
||||
td
|
||||
td
|
||||
td
|
||||
|
||||
- webmentions.each do |webmention|
|
||||
tr
|
||||
td
|
||||
= webmention.id
|
||||
td
|
||||
= webmention.author_name
|
||||
td
|
||||
div class="w-full"
|
||||
/ span class="px-2"
|
||||
/ select class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg" name="book_status" hx-params="book_status" hx-patch="/admin/books/#{book.id}" hx-trigger="change"
|
||||
/ option value="read" selected=(book.book_status == "read") Read
|
||||
/ option value="to-read" selected=(book.book_status == "to-read") To Read
|
||||
/ option value="reading" selected=(book.book_status == "reading") Reading
|
||||
span
|
||||
== webmention.content_html
|
||||
td
|
||||
a href="#{webmention.source_url}" Source
|
||||
td
|
||||
a href="#{webmention.target_url}" Target
|
||||
td
|
||||
- if webmention.published_at
|
||||
button hx-swap="afterend" hx-patch="/admin/webmentions/#{webmention.id}/archive" hx-trigger="click" Archive
|
||||
- else
|
||||
button hx-swap="afterend" hx-patch="/admin/webmentions/#{webmention.id}/publish" hx-trigger="click" Publish
|
15
slices/admin/views/webmentions/index.rb
Normal file
15
slices/admin/views/webmentions/index.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Views
|
||||
module Webmentions
|
||||
class Index < Admin::View
|
||||
include Deps["repos.webmention_repo"]
|
||||
|
||||
expose :webmentions do
|
||||
webmention_repo.list_all
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -64,7 +64,7 @@ module Micropub
|
||||
.published
|
||||
.combine(:tags, :trips, :webmentions)
|
||||
.node(:webmentions) { |webmention|
|
||||
webmention.where(type: "reply")
|
||||
webmention.published.where(type: "reply")
|
||||
}
|
||||
.where(slug: slug)
|
||||
.one!
|
||||
|
Reference in New Issue
Block a user