diff --git a/app/repos/post_repo.rb b/app/repos/post_repo.rb index 3e76135..1401bc8 100644 --- a/app/repos/post_repo.rb +++ b/app/repos/post_repo.rb @@ -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! diff --git a/config.ru b/config.ru index 7e82d0c..10f7c96 100644 --- a/config.ru +++ b/config.ru @@ -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 diff --git a/slices/admin/actions/webmentions/index.rb b/slices/admin/actions/webmentions/index.rb new file mode 100644 index 0000000..cc1a89f --- /dev/null +++ b/slices/admin/actions/webmentions/index.rb @@ -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 diff --git a/slices/admin/actions/webmentions/update.rb b/slices/admin/actions/webmentions/update.rb new file mode 100644 index 0000000..c9eb44f --- /dev/null +++ b/slices/admin/actions/webmentions/update.rb @@ -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 diff --git a/slices/admin/config/routes.rb b/slices/admin/config/routes.rb index 117eed4..832226f 100644 --- a/slices/admin/config/routes.rb +++ b/slices/admin/config/routes.rb @@ -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 diff --git a/slices/admin/repos/webmention_repo.rb b/slices/admin/repos/webmention_repo.rb new file mode 100644 index 0000000..af95fb9 --- /dev/null +++ b/slices/admin/repos/webmention_repo.rb @@ -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 diff --git a/slices/admin/templates/index.html.slim b/slices/admin/templates/index.html.slim index cedcb6b..84fc666 100644 --- a/slices/admin/templates/index.html.slim +++ b/slices/admin/templates/index.html.slim @@ -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 diff --git a/slices/admin/templates/webmentions/index.html.slim b/slices/admin/templates/webmentions/index.html.slim new file mode 100644 index 0000000..b515778 --- /dev/null +++ b/slices/admin/templates/webmentions/index.html.slim @@ -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 diff --git a/slices/admin/views/webmentions/index.rb b/slices/admin/views/webmentions/index.rb new file mode 100644 index 0000000..79f7034 --- /dev/null +++ b/slices/admin/views/webmentions/index.rb @@ -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 diff --git a/slices/micropub/repos/post_repo.rb b/slices/micropub/repos/post_repo.rb index e9d5ba5..6212667 100644 --- a/slices/micropub/repos/post_repo.rb +++ b/slices/micropub/repos/post_repo.rb @@ -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!