Add time machine
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -2,7 +2,7 @@
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
ruby "3.2.2"
|
||||
ruby "3.3.0.rc1"
|
||||
|
||||
gem "hanami", "2.1.0rc2"
|
||||
gem "hanami-router", "2.1.0rc2"
|
||||
|
10
Gemfile.lock
10
Gemfile.lock
@@ -277,6 +277,7 @@ GEM
|
||||
mime-types-data (3.2023.1003)
|
||||
mini_magick (4.12.0)
|
||||
mini_mime (1.1.5)
|
||||
mini_portile2 (2.8.5)
|
||||
minitest (5.20.0)
|
||||
multi_xml (0.6.0)
|
||||
mustermann (3.0.0)
|
||||
@@ -300,11 +301,8 @@ GEM
|
||||
net-ssh (7.2.0)
|
||||
netrc (0.11.0)
|
||||
nio4r (2.6.1)
|
||||
nokogiri (1.15.5-arm64-darwin)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.15.5-x86_64-darwin)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.15.5-x86_64-linux)
|
||||
nokogiri (1.15.5)
|
||||
mini_portile2 (~> 2.8.2)
|
||||
racc (~> 1.4)
|
||||
notiffany (0.1.3)
|
||||
nenv (~> 0.1)
|
||||
@@ -546,7 +544,7 @@ DEPENDENCIES
|
||||
webmention
|
||||
|
||||
RUBY VERSION
|
||||
ruby 3.2.2p53
|
||||
ruby 3.3.0.rc1
|
||||
|
||||
BUNDLED WITH
|
||||
2.3.22
|
||||
|
19
app/actions/timemachine/show.rb
Normal file
19
app/actions/timemachine/show.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Timemachine
|
||||
class Show < Action
|
||||
include Deps["views.timemachine.show"]
|
||||
|
||||
def handle(req, res)
|
||||
year, month, day = [
|
||||
req.params[:year],
|
||||
req.params[:month],
|
||||
req.params[:day]
|
||||
]
|
||||
|
||||
res.render show, year: year, month: month, day: day
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -15,6 +15,12 @@ module Adamantium
|
||||
.limit(5)
|
||||
.to_a
|
||||
end
|
||||
|
||||
def for_timemachine(date:)
|
||||
podcast_scrobbles
|
||||
.where(listened_at: TimeMath.day.floor(date)...TimeMath.day.advance(date, +1))
|
||||
.to_a
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -140,6 +140,20 @@ module Adamantium
|
||||
.to_a
|
||||
end
|
||||
|
||||
def posts_for_timemachine(date:)
|
||||
posts
|
||||
.where(post_type: "post")
|
||||
.where(published_at: TimeMath.day.floor(date)...TimeMath.day.advance(date, +1))
|
||||
.to_a
|
||||
end
|
||||
|
||||
def bookmarks_for_timemachine(date:)
|
||||
posts
|
||||
.where(post_type: "bookmark")
|
||||
.where(published_at: TimeMath.day.floor(date)...TimeMath.day.advance(date, +1))
|
||||
.to_a
|
||||
end
|
||||
|
||||
def for_rss
|
||||
posts
|
||||
.where(post_type: "post", location: nil)
|
||||
|
@@ -8,6 +8,7 @@ div class="mb-12 max-w-prose mx-auto text-gray-800 dark:text-gray-200"
|
||||
/ 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
|
||||
a class="block p-1 border border-blue-200 bg-blue-200 text-blue-900 hover:bg-blue-300 text-center rounded-lg" href="/tagged/weekly" 🔄 Week 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="/timemachine/#{Time.now.strftime("%Y/%m/%d")}" ⏳ Time machine
|
||||
|
||||
h2 class="text-xl" Explore everything else
|
||||
|
||||
|
@@ -4,7 +4,7 @@ div class="mb-8 h-entry"
|
||||
= post.display_title
|
||||
div class="e-content prose-p:mb-0 prose-img:my-2 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline p-name text-base prose prose-ul:list-none prose-ul:pl-0 prose-li:pl-0 text-gray-800 dark:text-gray-200 prose-a:dark:text-gray-100"
|
||||
== post.excerpt
|
||||
div class="grid gap-4 grid-flow-row grid-cols-4 grid-rows-1"
|
||||
div class="grid gap-4 grid-flow-row grid-cols-#{post.photos.count} grid-rows-1"
|
||||
-post.photos.each do |photo|
|
||||
img class="w-44 h-44 object-cover rounded" src=photo["value"]
|
||||
/ == render "shared/tags", tags: post.tags
|
||||
|
56
app/templates/timemachine/show.html.slim
Normal file
56
app/templates/timemachine/show.html.slim
Normal file
@@ -0,0 +1,56 @@
|
||||
div class="prose dark:prose-invert w-full max-w-6xl mx-auto px-4 m-4"
|
||||
div class="grid md:grid-cols-12 gap-5 p-4 m-2"
|
||||
div class="md:col-span-8 p-4"
|
||||
h2 class="mt-0" = display_date
|
||||
|
||||
a href="/timemachine/#{prev_date}" ← #{prev_date}
|
||||
|
||||
a class="inline-block px-2" href="/timemachine/#{today}" Today
|
||||
|
||||
- if next_date
|
||||
a href="/timemachine/#{next_date}" #{next_date} →
|
||||
|
||||
- if posts.count > 0
|
||||
div class="mt-4"
|
||||
- posts.each_with_index do |post, index|
|
||||
div class="#{"border-t-2" if index == 0} border-b-2 border-gray-200"
|
||||
- if post.photos.count == 0
|
||||
a href="/post/#{post.slug}"
|
||||
h3= post.name
|
||||
== post.excerpt
|
||||
- else
|
||||
div class="grid grid-cols-3 gap-2"
|
||||
- posts.each do |post|
|
||||
- if post.photos.count > 0
|
||||
- post.photos.each do |photo|
|
||||
a href="/post/#{post.slug}"
|
||||
img class="mb-0 rounded" src="#{photo["value"]}"
|
||||
a href="/post/#{post.slug}"
|
||||
= post.name
|
||||
- else
|
||||
p No posts
|
||||
|
||||
aside class="md:col-span-4 md:pt-0 p-2"
|
||||
- if bookmarks.count > 0
|
||||
h3 class="mt-0" Bookmarks
|
||||
|
||||
div
|
||||
ul
|
||||
- bookmarks.each do |bookmark|
|
||||
li
|
||||
a href="/bookmark/#{bookmark.slug}"
|
||||
= bookmark.name
|
||||
|
||||
- if podcasts.count > 0
|
||||
h3 class="mt-0" Podcasts
|
||||
|
||||
div
|
||||
ul
|
||||
- podcasts.each do |podcast|
|
||||
li
|
||||
a href=podcast.url
|
||||
=podcast.title
|
||||
div
|
||||
small = podcast.podcast_name
|
||||
/ h3 class="mt-0" Music
|
||||
/ h3 class="mt-0" Reading
|
59
app/views/timemachine/show.rb
Normal file
59
app/views/timemachine/show.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
require "time_math"
|
||||
|
||||
module Adamantium
|
||||
module Views
|
||||
module Timemachine
|
||||
class Show < Adamantium::View
|
||||
include Deps[
|
||||
"repos.post_repo",
|
||||
"repos.movie_repo",
|
||||
"repos.podcast_scrobble_repo",
|
||||
"repos.trip_repo"
|
||||
]
|
||||
|
||||
expose :posts do |date|
|
||||
post_repo.posts_for_timemachine(date: date.value).map do |post|
|
||||
Decorators::Posts::Decorator.new(post)
|
||||
end
|
||||
end
|
||||
|
||||
expose :bookmarks do |date|
|
||||
post_repo.bookmarks_for_timemachine(date: date.value).map do |post|
|
||||
Decorators::Bookmarks::Decorator.new(post)
|
||||
end
|
||||
end
|
||||
|
||||
expose :podcasts do |date|
|
||||
podcast_scrobble_repo.for_timemachine(date: date.value)
|
||||
end
|
||||
|
||||
expose :display_date do |date|
|
||||
date.strftime("%A, %d %B, %Y")
|
||||
end
|
||||
|
||||
expose :next_date do |date|
|
||||
today_to_tomorrow = TimeMath.measure(TimeMath(date.value).advance(:day, +1).call, Time.now)
|
||||
|
||||
unless today_to_tomorrow[:hours] < 0
|
||||
TimeMath.day.advance(date.value, +1)
|
||||
.strftime("%Y/%m/%d")
|
||||
end
|
||||
end
|
||||
|
||||
expose :today do
|
||||
Time.now
|
||||
.strftime("%Y/%m/%d")
|
||||
end
|
||||
|
||||
expose :prev_date do |date|
|
||||
TimeMath.day.advance(date.value, -1)
|
||||
.strftime("%Y/%m/%d")
|
||||
end
|
||||
|
||||
private_expose :date do |year:, month:, day:|
|
||||
DateTime.parse("#{year}-#{month}-#{day}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -50,6 +50,8 @@ module Adamantium
|
||||
|
||||
get "/bookshelf", to: "books.index"
|
||||
|
||||
get "/timemachine/:year/:month/:day", to: "timemachine.show"
|
||||
|
||||
redirect "deploying-a-hanami-app-to-fly-io", to: "/post/deploying-a-hanami-20-app-to-flyio"
|
||||
redirect "deploying-a-hanami-app-to-fly-io/", to: "/post/deploying-a-hanami-20-app-to-flyio"
|
||||
|
||||
|
Reference in New Issue
Block a user