Add posts from archive to weekly posts

This commit is contained in:
2023-03-06 16:05:54 +11:00
parent 142af0b42b
commit 72cc4cc3ee
4 changed files with 49 additions and 12 deletions

View File

@@ -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)

View File

@@ -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"

View File

@@ -1,10 +1,11 @@
a href=url class="block flex bg-pink-100 dark:bg-pink-600 rounded px-4 py-2 mb-12"
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=""
p class="hover:underline"
span class="font-semibold"= name
span by
span class="font-semibold"= artist

View File

@@ -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