diff --git a/app/actions/more/index.rb b/app/actions/more/index.rb new file mode 100644 index 0000000..0b639e3 --- /dev/null +++ b/app/actions/more/index.rb @@ -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 diff --git a/app/actions/posts/archive.rb b/app/actions/posts/archive.rb new file mode 100644 index 0000000..7b0268c --- /dev/null +++ b/app/actions/posts/archive.rb @@ -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 diff --git a/app/content/home.md b/app/content/home.md index e3e621d..ac01e25 100644 --- a/app/content/home.md +++ b/app/content/home.md @@ -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). diff --git a/app/content/pages/more.md b/app/content/pages/more.md new file mode 100644 index 0000000..e69de29 diff --git a/app/repos/post_repo.rb b/app/repos/post_repo.rb index d82808f..9c8d35a 100644 --- a/app/repos/post_repo.rb +++ b/app/repos/post_repo.rb @@ -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 diff --git a/app/repos/tag_repo.rb b/app/repos/tag_repo.rb index 9e9f338..ff277c8 100644 --- a/app/repos/tag_repo.rb +++ b/app/repos/tag_repo.rb @@ -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 diff --git a/app/templates/more/index.html.slim b/app/templates/more/index.html.slim new file mode 100644 index 0000000..ab839de --- /dev/null +++ b/app/templates/more/index.html.slim @@ -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 + diff --git a/app/templates/posts/archive.html.slim b/app/templates/posts/archive.html.slim new file mode 100644 index 0000000..aeb575e --- /dev/null +++ b/app/templates/posts/archive.html.slim @@ -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 · +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" + diff --git a/app/templates/posts/index.html.slim b/app/templates/posts/index.html.slim index 4a379b4..8538539 100644 --- a/app/templates/posts/index.html.slim +++ b/app/templates/posts/index.html.slim @@ -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 · div class="h-feed mb-12 max-w-prose mx-auto" - posts.each do |post| == render "shared/post", post: post diff --git a/app/templates/posts/show.html.slim b/app/templates/posts/show.html.slim index 76e7c4b..72dfb2d 100644 --- a/app/templates/posts/show.html.slim +++ b/app/templates/posts/show.html.slim @@ -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 diff --git a/app/views/more/index.rb b/app/views/more/index.rb new file mode 100644 index 0000000..998bea8 --- /dev/null +++ b/app/views/more/index.rb @@ -0,0 +1,8 @@ +module Adamantium + module Views + module More + class Index < View + end + end + end +end diff --git a/app/views/posts/archive.rb b/app/views/posts/archive.rb new file mode 100644 index 0000000..cd45415 --- /dev/null +++ b/app/views/posts/archive.rb @@ -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 diff --git a/app/views/posts/index.rb b/app/views/posts/index.rb index 5c20828..0513da7 100644 --- a/app/views/posts/index.rb +++ b/app/views/posts/index.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 5010615..402dee9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"