From 425e93c0563876ee71cb1920a1c12621cf38f40e Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sun, 27 Aug 2023 17:06:20 +1000 Subject: [PATCH] Add Summary to trips --- app/templates/trips/show.html.slim | 3 +++ config/app.rb | 3 ++- db/migrate/20230825091941_add_summary_to_trips.rb | 9 +++++++++ slices/admin/commands/trips/update.rb | 11 +++++++++-- slices/admin/templates/posts/show.html.slim | 2 ++ slices/admin/templates/trips/show.html.slim | 5 +++++ slices/admin/views/trips/show.rb | 8 +++++++- 7 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20230825091941_add_summary_to_trips.rb diff --git a/app/templates/trips/show.html.slim b/app/templates/trips/show.html.slim index eb27fbf..4467742 100644 --- a/app/templates/trips/show.html.slim +++ b/app/templates/trips/show.html.slim @@ -4,6 +4,9 @@ div class="mb-4 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:t h1 class="mb-0" #{trip.name} / p class="mt-2" class="text-gray-600 dark:text-gray-200 text-sm" (#{trip.start_date} - #{trip.end_date}) +div class="mb-4 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 bg-gray-100 p-2 rounded prose-p:mb-0 prose-ul:mt-0" + == trip.summary + div class="h-feed mb-12 max-w-prose mx-auto" - posts.each do |post| == render "shared/compact_post", post: post, trip: trip, first: post.id == posts.first.id, last: post.id == posts.last.id diff --git a/config/app.rb b/config/app.rb index a2000b4..41e5f09 100644 --- a/config/app.rb +++ b/config/app.rb @@ -21,7 +21,8 @@ module Adamantium config.logger.stream = "log/hanami.log" config.shared_app_component_keys += [ - "syndication.dayone" + "syndication.dayone", + "renderers.markdown" ] end end diff --git a/db/migrate/20230825091941_add_summary_to_trips.rb b/db/migrate/20230825091941_add_summary_to_trips.rb new file mode 100644 index 0000000..2120f61 --- /dev/null +++ b/db/migrate/20230825091941_add_summary_to_trips.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +ROM::SQL.migration do + change do + alter_table :trips do + add_column :summary, :text, default: nil + end + end +end diff --git a/slices/admin/commands/trips/update.rb b/slices/admin/commands/trips/update.rb index 3aa41e2..ee76c43 100644 --- a/slices/admin/commands/trips/update.rb +++ b/slices/admin/commands/trips/update.rb @@ -3,13 +3,20 @@ module Admin module Trips class Update include Dry::Monads[:result] - include Deps["repos.trip_repo"] + include Deps["repos.trip_repo", renderer: "renderers.markdown"] def call(id:, trip:) - trip_repo.update(id, trip) + trip_repo.update(id, prepare(trip: trip)) Success() end + + private + + def prepare(trip:) + trip[:summary] = renderer.call(content: trip[:summary]) + trip + end end end end diff --git a/slices/admin/templates/posts/show.html.slim b/slices/admin/templates/posts/show.html.slim index f32cd88..b995634 100644 --- a/slices/admin/templates/posts/show.html.slim +++ b/slices/admin/templates/posts/show.html.slim @@ -7,6 +7,8 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark: a href=url = name button hx-post="/admin/posts/#{post.id}/syndicate/day_one" Send to Day One + +// TODO: Add preview, save post, fix sending to DayOne 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 textarea class="text-gray-800 w-full border-blue-200 border-2 rounded p-2" x-data="{ resize: () => { $el.style.height = '5px'; $el.style.height = $el.scrollHeight + 'px' } }" x-init="resize()" @input="resize()" diff --git a/slices/admin/templates/trips/show.html.slim b/slices/admin/templates/trips/show.html.slim index ad11dd9..3e68fd5 100644 --- a/slices/admin/templates/trips/show.html.slim +++ b/slices/admin/templates/trips/show.html.slim @@ -13,6 +13,11 @@ div class="max-w-prose mx-auto mb-8 border-gray-400 border-b-4" label class="text-gray-800 dark:text-gray-200 mr-2" for="subtitle" Subtitle: input class="text-gray-800 p-1 border border-gray-400" type="text" id="subtitle" name="trip[subtitle]" value=trip.subtitle + div class="mb-4" + label class="text-gray-800 dark:text-gray-200 mr-2" for="subtitle" Summary: + textarea id="summary" name="trip[summary]" class="text-gray-800 w-full border-blue-200 border-2 rounded p-2" x-data="{ resize: () => { $el.style.height = '5px'; $el.style.height = $el.scrollHeight + 'px' } }" x-init="resize()" @input="resize()" + == trip_summary + div class="mb-4" button class="rounded bg-blue-100 hover:bg-blue-200 text-blue-600 px-2 hover:cursor-pointer" type="submit" = "Update" diff --git a/slices/admin/views/trips/show.rb b/slices/admin/views/trips/show.rb index 97b6a4a..76826eb 100644 --- a/slices/admin/views/trips/show.rb +++ b/slices/admin/views/trips/show.rb @@ -1,3 +1,5 @@ +require "reverse_markdown" + module Admin module Views module Trips @@ -5,7 +7,11 @@ module Admin include Deps["repos.trip_repo", "repos.post_repo"] expose :trip do |id:| - trip_repo.fetch(id) + trip = trip_repo.fetch(id) + end + + expose :trip_summary do |trip| + ReverseMarkdown.convert(trip.summary, unknown_tags: :pass_through, github_flavored: true).to_s end expose :posts do |trip|