From 15cdd40f75269b538e9b79bbd040be2473e72125 Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sun, 11 Jun 2023 14:25:30 +1000 Subject: [PATCH] Syndicate to Day One from Admin pages --- config/app.rb | 4 ++++ config/routes.rb | 2 ++ slices/admin/actions/posts/show.rb | 15 +++++++++++++++ slices/admin/actions/posts/syndicate.rb | 15 +++++++++++++++ slices/admin/commands/posts/syndicate.rb | 20 ++++++++++++++++++++ slices/admin/repos/post_repo.rb | 4 ++++ slices/admin/templates/posts/index.html.slim | 4 ++++ slices/admin/templates/posts/show.html.slim | 12 ++++++++++++ slices/admin/views/posts/show.rb | 13 +++++++++++++ 9 files changed, 89 insertions(+) create mode 100644 slices/admin/actions/posts/show.rb create mode 100644 slices/admin/actions/posts/syndicate.rb create mode 100644 slices/admin/commands/posts/syndicate.rb create mode 100644 slices/admin/templates/posts/show.html.slim create mode 100644 slices/admin/views/posts/show.rb diff --git a/config/app.rb b/config/app.rb index 83e8ac2..5c62fc1 100644 --- a/config/app.rb +++ b/config/app.rb @@ -17,5 +17,9 @@ module Adamantium config.logger.level = :debug config.logger.stream = "log/hanami.log" + + config.shared_app_component_keys += [ + "syndication.dayone" + ] end end diff --git a/config/routes.rb b/config/routes.rb index 335d88c..a281a09 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,6 +84,8 @@ module Adamantium delete "/posts/:id", to: "posts.delete" post "/posts/:id/archive", to: "posts.archive" post "/posts/:id/publish", to: "posts.publish" + get "/posts/:id", to: "posts.show" + post "/posts/:id/syndicate/:target", to: "posts.syndicate" get "/media", to: "photos.index" diff --git a/slices/admin/actions/posts/show.rb b/slices/admin/actions/posts/show.rb new file mode 100644 index 0000000..44615fa --- /dev/null +++ b/slices/admin/actions/posts/show.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Admin + module Actions + module Posts + class Show < Admin::Action + include Deps["views.posts.show"] + + def handle(req, res) + res.render show, id: req.params[:id] + end + end + end + end +end diff --git a/slices/admin/actions/posts/syndicate.rb b/slices/admin/actions/posts/syndicate.rb new file mode 100644 index 0000000..61fdfcd --- /dev/null +++ b/slices/admin/actions/posts/syndicate.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Admin + module Actions + module Posts + class Syndicate < Admin::Action + include Deps["commands.posts.syndicate"] + + def handle(req, res) + syndicate.(post_id: req.params[:id], target: req.params[:target]) + end + end + end + end +end diff --git a/slices/admin/commands/posts/syndicate.rb b/slices/admin/commands/posts/syndicate.rb new file mode 100644 index 0000000..54252e0 --- /dev/null +++ b/slices/admin/commands/posts/syndicate.rb @@ -0,0 +1,20 @@ +require "readability" +require "down" + +module Admin + module Commands + module Posts + class Syndicate + include Dry::Monads[:result] + include Deps["repos.post_repo", "syndication.dayone"] + + def call(post_id:, target:) + post = post_repo.find(id: post_id) + + dayone.(name: post[:name], content: post[:content]) if target.to_sym == :day_one + Success() + end + end + end + end +end diff --git a/slices/admin/repos/post_repo.rb b/slices/admin/repos/post_repo.rb index d168c7b..ec64e8c 100644 --- a/slices/admin/repos/post_repo.rb +++ b/slices/admin/repos/post_repo.rb @@ -41,6 +41,10 @@ module Admin .to_a end + def find(id:) + posts.where(id: id).one! + end + def delete(id:) posts.where(id: id).delete end diff --git a/slices/admin/templates/posts/index.html.slim b/slices/admin/templates/posts/index.html.slim index c0b0a57..217324c 100644 --- a/slices/admin/templates/posts/index.html.slim +++ b/slices/admin/templates/posts/index.html.slim @@ -20,6 +20,8 @@ div class="max-w-prose mx-auto" x-data="{ activeTab: 0 }" small class="text-gray-400 dark:text-gray-600" = post.slug td = post.published_at&.strftime("%d %b %Y") + td + a href="/admin/posts/#{post.id}" edit td button class="text-red-600" hx-delete="/admin/posts/#{post.id}" hx-target="#post-#{post.id}" delete td @@ -34,6 +36,8 @@ div class="max-w-prose mx-auto" x-data="{ activeTab: 0 }" small class="text-gray-400 dark:text-gray-600" = post.slug td = post.published_at&.strftime("%d %b %Y") + td + a href="/admin/posts/#{post.id}" edit td button class="text-red-600" hx-delete="/admin/posts/#{post.id}" hx-target="#post-#{post.id}" delete td diff --git a/slices/admin/templates/posts/show.html.slim b/slices/admin/templates/posts/show.html.slim new file mode 100644 index 0000000..efbf6da --- /dev/null +++ b/slices/admin/templates/posts/show.html.slim @@ -0,0 +1,12 @@ + +div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 bg-red-100" + h3 Syndicated to + ul + - post.syndication_sources.to_a.each do |name, url| + li + a href=url + = name + button hx-post="/admin/posts/#{post.id}/syndicate/day_one" Send to Day One +article class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline prose-img:rounded" + h1= post.name + == post.content \ No newline at end of file diff --git a/slices/admin/views/posts/show.rb b/slices/admin/views/posts/show.rb new file mode 100644 index 0000000..5d8e3c1 --- /dev/null +++ b/slices/admin/views/posts/show.rb @@ -0,0 +1,13 @@ +module Admin + module Views + module Posts + class Show < Admin::View + include Deps["repos.post_repo"] + + expose :post do |id:| + post_repo.find(id: id) + end + end + end + end +end