Add top track to weekly post
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -34,6 +34,8 @@ gem "ogpr"
|
||||
gem "ruby-filemagic", git: "https://github.com/dnitza/ruby-filemagic", branch: "master"
|
||||
gem "webmention"
|
||||
gem "sanitize"
|
||||
gem "time_math2", require: "time_math"
|
||||
gem "lastfm", "~> 1.27"
|
||||
|
||||
group :cli, :development do
|
||||
gem "hanami-reloader"
|
||||
|
@@ -214,6 +214,9 @@ GEM
|
||||
nokogiri (>= 1.13)
|
||||
json (2.6.3)
|
||||
language_server-protocol (3.17.0.3)
|
||||
lastfm (1.27.4)
|
||||
httparty
|
||||
xml-simple
|
||||
link-header-parser (5.0.0)
|
||||
listen (3.8.0)
|
||||
rb-fsevent (~> 0.10, >= 0.10.3)
|
||||
@@ -360,6 +363,7 @@ GEM
|
||||
temple (0.10.0)
|
||||
thor (1.2.1)
|
||||
tilt (2.0.11)
|
||||
time_math2 (0.1.1)
|
||||
timecop (0.9.6)
|
||||
transproc (1.1.1)
|
||||
unf (0.1.4)
|
||||
@@ -370,6 +374,8 @@ GEM
|
||||
http (~> 5.0)
|
||||
indieweb-endpoints (~> 8.0)
|
||||
nokogiri (>= 1.13)
|
||||
xml-simple (1.1.9)
|
||||
rexml
|
||||
zeitwerk (2.6.7)
|
||||
|
||||
PLATFORMS
|
||||
@@ -397,6 +403,7 @@ DEPENDENCIES
|
||||
hanami-validations (~> 2.0.0)
|
||||
hanami-view!
|
||||
httparty
|
||||
lastfm (~> 1.27)
|
||||
ogpr
|
||||
pg
|
||||
pinboard!
|
||||
@@ -412,6 +419,7 @@ DEPENDENCIES
|
||||
sanitize
|
||||
slim
|
||||
standardrb
|
||||
time_math2
|
||||
timecop
|
||||
webmention
|
||||
|
||||
|
25
app/actions/posts/top_tracks.rb
Normal file
25
app/actions/posts/top_tracks.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Posts
|
||||
class TopTracks < Action
|
||||
include Deps["views.posts.top_tracks", query: "queries.posts.top_tracks"]
|
||||
|
||||
def handle(req, res)
|
||||
res.content_type = "Application/JSON"
|
||||
res.status = 200
|
||||
tracks = query.call(slug: req.params[:slug])
|
||||
|
||||
track = if tracks.is_a? Array
|
||||
tracks.first
|
||||
else
|
||||
tracks
|
||||
end
|
||||
|
||||
if track
|
||||
res.render top_tracks, track: track
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
app/queries/posts/top_tracks.rb
Normal file
20
app/queries/posts/top_tracks.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require "lastfm"
|
||||
require "time_math"
|
||||
|
||||
module Adamantium
|
||||
module Queries
|
||||
module Posts
|
||||
class TopTracks
|
||||
include Deps["settings", "repos.post_repo"]
|
||||
|
||||
def call(slug:)
|
||||
post = post_repo.fetch!(slug)
|
||||
|
||||
lastfm = Lastfm.new(settings.lastfm_api_key, settings.lastfm_secret)
|
||||
|
||||
lastfm.user.get_weekly_track_chart(user: "dNitza", from: TimeMath.week.floor(post.published_at).to_i, to: TimeMath.week.ceil(post.published_at).to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -24,6 +24,10 @@ article class="h-entry"
|
||||
- if post.location
|
||||
img class="shadow-solid shadow-pink-100 dark:shadow-pink-200 rounded mb-4" src=post.large_map
|
||||
|
||||
- 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 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"
|
||||
|
7
app/templates/posts/top_tracks.html.slim
Normal file
7
app/templates/posts/top_tracks.html.slim
Normal file
@@ -0,0 +1,7 @@
|
||||
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"
|
||||
img class="rounded h-34 w-34 my-auto" src=image
|
||||
div
|
||||
p class="text-lg" Top track this week
|
||||
p class="text-xl"= "#{name} by #{artist}"
|
||||
|
25
app/views/posts/top_tracks.rb
Normal file
25
app/views/posts/top_tracks.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Adamantium
|
||||
module Views
|
||||
module Posts
|
||||
class TopTracks < Adamantium::View
|
||||
config.layout = false
|
||||
|
||||
expose :name do |track:|
|
||||
track["name"]
|
||||
end
|
||||
|
||||
expose :artist do |track:|
|
||||
track.dig("artist", "content")
|
||||
end
|
||||
|
||||
expose :image do |track:|
|
||||
track["image"].detect { |i| i["size"] == "small" }["content"]
|
||||
end
|
||||
|
||||
expose :url do |track:|
|
||||
track["url"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -16,6 +16,7 @@ module Adamantium
|
||||
end
|
||||
|
||||
get "/", to: "site.home"
|
||||
get "/post/top_tracks/:slug", to: "posts.top_tracks"
|
||||
get "/post/:slug", to: "posts.show"
|
||||
get "/posts", to: "posts.index"
|
||||
|
||||
|
@@ -25,6 +25,9 @@ module Adamantium
|
||||
setting :pingback_url, default: nil
|
||||
setting :webmention_token, default: nil
|
||||
|
||||
setting :lastfm_api_key, default: nil
|
||||
setting :lastfm_secret, default: nil
|
||||
|
||||
# Micropub endpoints
|
||||
setting :micropub_media_endpoint, default: "", constructor: Types::Params::String
|
||||
|
||||
|
Reference in New Issue
Block a user