More details on posts and error reporting

This commit is contained in:
2023-05-31 22:12:48 +10:00
parent b034ecb3ab
commit 2c1122c9d7
20 changed files with 177 additions and 39 deletions

View File

@@ -9,12 +9,17 @@ require "dry/matcher/result_matcher"
module Adamantium
class Action < Hanami::Action
include Deps["logger", "settings", not_found_view: "views.not_found"]
include Deps["logger",
"settings",
not_found_view: "views.not_found",
error_view: "views.error",
sentry: "sentry.client"]
include Dry::Matcher.for(:handle, with: Dry::Matcher::ResultMatcher)
include Dry::Monads[:result]
handle_exception ROM::TupleCountMismatchError => :not_found
handle_exception StandardError => :handle_error
def authenticate!(req, res)
if Hanami.env == :development || Hanami.env == :test
@@ -47,6 +52,16 @@ module Adamantium
res.render not_found_view
end
def handle_error(req, res, exception)
raise exception if settings.raise_exceptions
sentry.capture_exception(exception)
res.status = 500
res.render error_view
res.headers["Cache-Control"] = "no-store, max-age=0"
end
def verify_scope(req:, scope:)
req.env[:scopes].include? scope
end

View File

@@ -97,6 +97,16 @@ module Adamantium
:post
end
def posted_in
if name.nil?
:statuses
elsif location.nil?
:posts
else
:places
end
end
private
# e.g. geo:-37.75188,144.90417;u=35

View File

@@ -27,6 +27,9 @@ div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex"
= "Published "
time class="dt-published" datetime=bookmark.machine_published_at
= bookmark.display_published_at
p
span in&nbsp;
a class="hover:underline" href="/bookmarks" bookmarks
span class="text-right flex-1"
== render "shared/tags", tags: bookmark.tags

View File

@@ -0,0 +1,2 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 There was an error!

View File

@@ -4,16 +4,16 @@ div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h2 class="text-xl" Explore posts
div class="grid grid-cols-4 grid-flow-col gap-2 mb-6"
a class="block p-1 border border-lime-200 bg-lime-200 text-lime-900 hover:bg-lime-300 text-center rounded-lg" href="/tags" 🔖 By tag
/ a class="block p-1 border border-lime-200 bg-lime-300 text-lime-900 hover:bg-lime-200 text-center rounded-lg" href="/years" 🗓️ By year
a class="block p-1 border border-lime-200 bg-lime-200 text-lime-900 hover:bg-lime-300 text-center rounded-lg" href="/posts" 🪧 All posts
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/tags" 🔖 By tag
/ a class="block p-1 border border-blue-200 bg-blue-300 text-blue-900 hover:bg-blue-200 text-center rounded-lg" href="/years" 🗓️ By year
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/posts" 🪧 All posts
h2 class="text-xl" Explore everything else
div class="grid grid-cols-4 grid-flow-col gap-2 mb-6"
a class="block p-1 border border-lime-200 bg-lime-200 text-lime-900 hover:bg-lime-300 text-center rounded-lg" href="/colophon" 🧱 Colophon
a class="block p-1 border border-lime-200 bg-lime-200 text-lime-900 hover:bg-lime-300 text-center rounded-lg" href="/hikes" 🥾 Hikes
a class="block p-1 border border-lime-200 bg-lime-200 text-lime-900 hover:bg-lime-300 text-center rounded-lg" href="/movies" 🍿 Movies
a class="block p-1 border border-lime-200 bg-lime-200 text-lime-900 hover:bg-lime-300 text-center rounded-lg" href="/trips" 🛫 Trips
/ a class="block p-1 border border-lime-200 bg-lime-300 text-lime-900 hover:bg-lime-200 text-center rounded-lg" href="/art" 🎨 Art things
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/colophon" 🧱 Colophon
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/hikes" 🥾 Hikes
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/movies" 🍿 Movies
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/trips" 🛫 Trips
/ a class="block p-1 border border-blue-200 bg-blue-300 text-blue-900 hover:bg-blue-200 text-center rounded-lg" href="/art" 🎨 Art things

View File

@@ -1,3 +1,2 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Not Found!

View File

@@ -89,6 +89,14 @@ article class="h-entry"
p
a class="p-author h-card" href=Hanami.app.settings.micropub_site_url
= "by #{Hanami.app.settings.site_name}"
p
span in&nbsp;
- if post.posted_in == :posts
a class="hover:underline" href="/posts" posts
- if post.posted_in == :places
a class="hover:underline" href="/places" places
- if post.posted_in == :statuses
a class="hover:underline" href="/statuses" statuses
span class="text-right flex-1 leading-6"
== render "shared/tags", tags: post.tags
div class="mb-2 max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex"

6
app/views/error.rb Normal file
View File

@@ -0,0 +1,6 @@
module Adamantium
module Views
class Error < View
end
end
end