diff --git a/app/repos/post_repo.rb b/app/repos/post_repo.rb index b09229e..dd50bd9 100644 --- a/app/repos/post_repo.rb +++ b/app/repos/post_repo.rb @@ -124,6 +124,25 @@ module Adamantium .one end + def from_the_archives(start_date:, end_date:) + # SELECT * FROM posts + # WHERE EXTRACT(month FROM "published_at") >= 2 + # WHERE EXTRACT(month FROM "published_at") <= 2+ + # AND EXTRACT(day FROM "published_at") > 20 + # AND EXTRACT(day FROM "published_at") < 27 + # AND post_type = 'post'; + + posts + .where(post_type: "post") + .published + .where { Sequel.extract(:year, :published_at) < start_date.year } + .where { Sequel.extract(:month, :published_at) >= start_date.month } + .where { Sequel.extract(:month, :published_at) <= end_date.month } + .where { Sequel.extract(:day, :published_at) >= start_date.day } + .where { Sequel.extract(:day, :published_at) <= end_date.day } + .to_a + end + def for_rss posts .where(post_type: "post", location: nil) diff --git a/app/templates/posts/show.html.slim b/app/templates/posts/show.html.slim index 044e38a..c74bd6f 100644 --- a/app/templates/posts/show.html.slim +++ b/app/templates/posts/show.html.slim @@ -26,8 +26,16 @@ article class="h-entry" - if post.tags.map(&:label).include? "weekly" div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex" - div class="mx-auto" hx-get="/post/top_tracks/#{post.slug}" hx-trigger="load" - + div hx-get="/post/top_tracks/#{post.slug}" hx-trigger="load" + + - if past_posts.count > 0 + div class="block grow bg-blue-100 dark:bg-blue-600 rounded px-4 py-2 mb-12" + p class="text-sm mb-0" This week, years ago + ul class="mt-0" + - past_posts.each do |past_post| + li class="m-0" + a class="hover:underline" href=past_post.permalink + = "#{past_post.display_title} (#{past_post.published_at.year})" div class="mb-4 max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600" div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex" diff --git a/app/templates/posts/top_tracks.html.slim b/app/templates/posts/top_tracks.html.slim index 71ebb2f..7c742ce 100644 --- a/app/templates/posts/top_tracks.html.slim +++ b/app/templates/posts/top_tracks.html.slim @@ -1,11 +1,12 @@ -a href=url class="block flex bg-pink-100 dark:bg-pink-600 rounded px-4 py-2 mb-12" - div class="mr-4 my-auto" - div class="w-34 h-34 my-auto text-[2.041rem] block dark:hidden" 👩🏼‍🎤 - div class="w-34 h-34 my-auto text-[2.041rem] hidden dark:block" 👨🏽‍🎤 - div - p class="text-sm" Top track this week - p class="" - span class="font-semibold"= name - span by - span class="font-semibold"= artist +div class="mx-auto mr-4" + a href=url class="block flex bg-pink-100 dark:bg-pink-600 rounded px-4 py-2 mb-12" + div class="mr-4 my-auto" + div class="w-34 h-34 my-auto text-[2.041rem] block dark:hidden" 👩🏼‍🎤 + div class="w-34 h-34 my-auto text-[2.041rem] hidden dark:block" 👨🏽‍🎤 + div + p class="text-sm" Top track this week + p class="hover:underline" + span class="font-semibold"= name + span by + span class="font-semibold"= artist diff --git a/app/views/posts/show.rb b/app/views/posts/show.rb index 4398cf8..7ffa375 100644 --- a/app/views/posts/show.rb +++ b/app/views/posts/show.rb @@ -1,3 +1,5 @@ +require "time_math" + module Adamantium module Views module Posts @@ -7,6 +9,13 @@ module Adamantium expose :post do |slug:| Decorators::Posts::Decorator.new(post_repo.fetch!(slug)) end + + expose :past_posts do |post| + start_date = TimeMath.week.floor(post.published_at) + end_date = TimeMath.week.ceil(post.published_at) + posts = post_repo.from_the_archives(start_date: start_date, end_date: end_date) + posts.map { |p| Decorators::Posts::Decorator.new(p) } + end end end end