Add “more” page

This commit is contained in:
2023-04-25 20:45:16 +10:00
parent 7155d19d84
commit ad3f557dc2
14 changed files with 140 additions and 7 deletions

13
app/actions/more/index.rb Normal file
View File

@@ -0,0 +1,13 @@
module Adamantium
module Actions
module More
class Index < Action
include Deps["views.more.index"]
def handle(req, res)
res.render index
end
end
end
end
end

View File

@@ -0,0 +1,15 @@
module Adamantium
module Actions
module Posts
class Archive < Action
include Deps["views.posts.archive"]
def handle(req, res)
year = req.params[:year]
res.render archive, year: year
end
end
end
end
end

View File

@@ -1,4 +1,4 @@
Hi! 👋 I'm Daniel, a software engineer living in Canberra, Australia.
Welcome to my personal site! This is where I post the things I have [written](/posts), the [photos](/photos) I have taken, the [bookmarks](/bookmarks) I have saved, and the [places](/places) I have been.
Welcome to my personal site! This is where I post the things I have [written](/posts), the [photos](/photos) I have taken, the [bookmarks](/bookmarks) I have saved, the [places](/places) I have been, and a whole bunch [more](/more).

View File

View File

@@ -53,6 +53,16 @@ module Adamantium
posts.post_tags.where(post_id: post_id, tag_id: tag[:id]).changeset(:delete).commit if tag
end
def by_year(year:)
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.published
.where { Sequel.&(Sequel.extract(:year, :published_at) =~ year) }
.combine(:tags)
.to_a
end
def post_listing(limit: nil)
posts
.where(post_type: "post", location: nil)
@@ -198,6 +208,17 @@ module Adamantium
delete_post = posts.where(slug: slug).command(:update)
delete_post.call(published_at: Time.now)
end
def post_years
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.published
.dataset
.group_and_count(Sequel.extract(:year, :published_at).as(:year))
.order(:year)
.to_a
end
end
end
end

View File

@@ -4,6 +4,12 @@ module Adamantium
def fetch!(slug)
tags.where(slug: slug).one!
end
def list
tags
.order(Sequel.function(:lower, :label))
.to_a
end
end
end
end

View File

@@ -0,0 +1,16 @@
div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 class="text-4xl font-extrabold" More
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-300 text-lime-900 hover:bg-lime-200 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-300 text-lime-900 hover:bg-lime-200 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-300 text-lime-900 hover:bg-lime-200 text-center rounded-lg" href="/colophon" 🧱 Colophon
a class="block p-1 border border-lime-200 bg-lime-300 text-lime-900 hover:bg-lime-200 text-center rounded-lg" href="/hikes" 🥾 Hikes

View File

@@ -0,0 +1,16 @@
div class="mb-4 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Archive: #{year}
div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200"
nav class="space-x-1 text-sm md:text-sm uppercase md:block"
span Archive:
- post_years.each do |y|
a href="/posts/archive/#{y}" class="text-sm hover:text-gray-400 #{year.to_s == y.to_s ? 'underline decoration-wavy' : ''}"= y
- if y != post_years.last
span &middot;
div class="h-feed mb-12 max-w-prose mx-auto"
- posts.each do |post|
== render "shared/post", post: post
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -1,6 +1,13 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
div class="mb-4 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Writing
div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200"
nav class="space-x-1 text-sm md:text-sm uppercase md:block"
span Archive:
- post_years.each do |year|
a href="/posts/archive/#{year}" class="text-sm hover:text-gray-400"= year
- if year != post_years.last
span &middot;
div class="h-feed mb-12 max-w-prose mx-auto"
- posts.each do |post|
== render "shared/post", post: post

View File

@@ -1,9 +1,15 @@
article class="h-entry"
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 class="p-name"
h1 class="p-name mb-2"
a class="u-url" href=post.permalink
= post.display_title
nav class="space-x-1 text-sm md:text-sm md:block"
- if post.location || post.photos? || post.videos?
span See more:
- if post.location
a href="/places" places
- if post.photos? || post.videos?
a href="/photos" photos
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"
div class="e-content"
== post.content

8
app/views/more/index.rb Normal file
View File

@@ -0,0 +1,8 @@
module Adamantium
module Views
module More
class Index < View
end
end
end
end

View File

@@ -0,0 +1,21 @@
module Adamantium
module Views
module Posts
class Archive < View
include Deps["repos.post_repo"]
expose :year do |year:|
year
end
expose :posts do |year:|
post_repo.by_year(year: year).map { |post| Decorators::Posts::Decorator.new(post) }
end
expose :post_years do
post_repo.post_years.map { |py| py[:year].to_i }
end
end
end
end
end

View File

@@ -9,6 +9,10 @@ module Adamantium
Decorators::Posts::Decorator.new(post)
end
end
expose :post_years do
post_repo.post_years.map { |py| py[:year].to_i }
end
end
end
end

View File

@@ -19,7 +19,7 @@ module Adamantium
get "/post/top_tracks/:slug", to: "posts.top_tracks"
get "/post/:slug", to: "posts.show"
get "/posts", to: "posts.index"
# get "/posts/archive/:year", to: "posts.archive"
get "/posts/archive/:year", to: "posts.archive"
get "/bookmarks", to: "bookmarks.index"
get "/bookmarks/metadata/:id", to: "bookmarks.metadata"
@@ -29,7 +29,7 @@ module Adamantium
get "/places", to: "places.index"
get "/statuses", to: "statuses.index"
# get "/tags", to: "tags.index"
get "/tags", to: "tags.index"
get "/tagged/:slug", to: "tags.show"
get "/key", to: "key.show" if Hanami.app.settings.micropub_pub_key
@@ -37,7 +37,7 @@ module Adamantium
get "/feeds/rss", to: "feeds.rss"
get "/feeds/statuses_rss", to: "feeds.statuses_rss"
# get "/more", to: "more.index"
get "/more", to: "more.index"
get "/hikes", to: "workouts.index"
post "/workouts", to: "workouts.create"