diff --git a/Gemfile b/Gemfile index a5a3da6..8b9d62a 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem "reverse_markdown" gem "rexml" gem "babosa" gem "pinboard", git: "https://github.com/dnitza/pinboard", branch: "master" +gem "ogpr" group :cli, :development do gem "hanami-reloader" diff --git a/Gemfile.lock b/Gemfile.lock index 47a331b..9541d27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,6 +52,8 @@ GEM database_cleaner-core (~> 2.0.0) sequel diff-lcs (1.5.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) dotenv (2.8.1) dry-auto_inject (1.0.0) dry-core (~> 1.0, < 2) @@ -178,6 +180,9 @@ GEM dry-validation (>= 1.10, < 2) zeitwerk (~> 2.6.0) hansi (0.2.1) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) @@ -191,6 +196,9 @@ GEM rb-inotify (~> 0.9, >= 0.9.10) lumberjack (1.2.8) method_source (1.0.0) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2022.0105) mini_mime (1.1.2) multi_xml (0.6.0) mustermann (3.0.0) @@ -202,6 +210,7 @@ GEM net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) net-ssh (7.0.1) + netrc (0.11.0) nio4r (2.5.8) nokogiri (1.14.1-x86_64-darwin) racc (~> 1.4) @@ -210,6 +219,9 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + ogpr (1.1.0) + nokogiri (~> 1.8) + rest-client (~> 2.1.0) parallel (1.22.1) parser (3.2.0.0) ast (~> 2.4.1) @@ -230,6 +242,11 @@ GEM ffi (~> 1.0) redcarpet (3.6.0) regexp_parser (2.6.2) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (2.1.1) nokogiri rexml (3.2.5) @@ -314,6 +331,9 @@ GEM tilt (2.0.11) timecop (0.9.6) transproc (1.1.1) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) unicode-display_width (2.4.2) zeitwerk (2.6.6) @@ -342,6 +362,7 @@ DEPENDENCIES hanami-validations (~> 2.0.0) hanami-view! httparty + ogpr pg pinboard! puma diff --git a/app/actions/bookmarks/metadata.rb b/app/actions/bookmarks/metadata.rb new file mode 100644 index 0000000..bbaecd5 --- /dev/null +++ b/app/actions/bookmarks/metadata.rb @@ -0,0 +1,13 @@ +module Adamantium + module Actions + module Bookmarks + class Metadata < Action + include Deps["views.bookmarks.metadata"] + + def handle(req, res) + res.render metadata, id: req.params[:id] + end + end + end + end +end diff --git a/app/templates/bookmarks/metadata.html.slim b/app/templates/bookmarks/metadata.html.slim new file mode 100644 index 0000000..459b57d --- /dev/null +++ b/app/templates/bookmarks/metadata.html.slim @@ -0,0 +1,7 @@ +- if image + div class="col-span-1" + img class="rounded h-16" src=image + +div class="#{image ? 'col-span-4' : 'col-span-5'}" + h6= title + small= description diff --git a/app/templates/bookmarks/show.html.slim b/app/templates/bookmarks/show.html.slim index a0d5e37..636f469 100644 --- a/app/templates/bookmarks/show.html.slim +++ b/app/templates/bookmarks/show.html.slim @@ -8,6 +8,8 @@ div class="mb-12 prose max-w-prose mx-auto text-gray-800 dark:text-gray-200" == bookmark.content +div class="prose max-w-prose mx-auto text-gray-800 dark:text-gray-200 grid grid-cols-5 gap-2" hx-get="/bookmarks/metadata/#{bookmark.id}" hx-trigger="load" + div class="mb-8 max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600" div class="mb-2 max-w-prose mx-auto text-gray-800 dark:text-gray-200 flex" diff --git a/app/templates/layouts/app.html.slim b/app/templates/layouts/app.html.slim index 53ac997..dac2adc 100644 --- a/app/templates/layouts/app.html.slim +++ b/app/templates/layouts/app.html.slim @@ -20,7 +20,7 @@ html script data-domain="dnitza.com" src="https://stats.dnitza.com/js/script.js" defer="true" - / script src="https://unpkg.com/htmx.org@1.8.4" integrity="sha384-wg5Y/JwF7VxGk4zLsJEcAojRtlVp1FKKdGy1qN+OMtdq72WRvX/EdRdqg/LOhYeV" crossorigin="anonymous" + script src="https://unpkg.com/htmx.org@1.8.4" integrity="sha384-wg5Y/JwF7VxGk4zLsJEcAojRtlVp1FKKdGy1qN+OMtdq72WRvX/EdRdqg/LOhYeV" crossorigin="anonymous" - if Hanami.app.settings.micropub_pub_key link rel="pgpkey" href="/key" diff --git a/app/views/bookmarks/metadata.rb b/app/views/bookmarks/metadata.rb new file mode 100644 index 0000000..ab08ece --- /dev/null +++ b/app/views/bookmarks/metadata.rb @@ -0,0 +1,30 @@ +require "ogpr" + +module Adamantium + module Views + module Bookmarks + class Metadata < View + include Deps["repos.post_repo"] + + config.layout = nil + + expose :description do |og_data| + og_data.description + end + + expose :title do |og_data| + og_data.title + end + + expose :image do |og_data| + og_data.image + end + + private_expose :og_data do |id:| + url = post_repo.find!(id).url + Ogpr.fetch(url) + end + end + end + end +end diff --git a/config/app.rb b/config/app.rb index 9903f04..2d4c427 100644 --- a/config/app.rb +++ b/config/app.rb @@ -6,6 +6,7 @@ module Adamantium class App < Hanami::App config.actions.content_security_policy[:script_src] += " https://gist.github.com" config.actions.content_security_policy[:script_src] += " *.dnitza.com" + config.actions.content_security_policy[:script_src] += " https://unpkg.com/htmx.org@1.8.4" config.actions.content_security_policy[:connect_src] += " https://stats.dnitza.com/api/event" config.logger.level = :debug diff --git a/config/puma.rb b/config/puma.rb index b93a0a9..e33d5bd 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -12,6 +12,6 @@ on_worker_boot do Hanami.shutdown end -pidfile ENV.fetch("PIDFILE") { "tmp/pids/puma.pid" } +pidfile ENV.fetch("PIDFILE", "tmp/pids/puma.pid") preload_app! diff --git a/config/routes.rb b/config/routes.rb index 28bdf9f..40ae5bb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ module Adamantium get "/posts", to: "posts.index" get "/bookmarks", to: "bookmarks.index" + get "/bookmarks/metadata/:id", to: "bookmarks.metadata" get "/bookmark/:slug", to: "bookmarks.show" get "/tagged/:slug", to: "tags.show"