Add more endpoints for now page

This commit is contained in:
2024-04-01 19:13:18 +11:00
parent 23bc0134d6
commit cbdc61c359
13 changed files with 128 additions and 28 deletions

View File

@@ -0,0 +1,15 @@
require "time_math"
module Main
module Actions
module PastWeek
class Index < Action
include Deps["views.past_week.index"]
def handle(req, res)
res.body = cache(key: "past_week", content_proc: -> { index.call.to_str })
end
end
end
end
end

View File

@@ -0,0 +1,15 @@
require "time_math"
module Main
module Actions
module RecentlyPlayedGames
class Index < Action
include Deps["views.recently_played_games.index"]
def handle(req, res)
res.body = cache(key: "recently_played_games", content_proc: -> { index.call.to_str })
end
end
end
end
end

View File

@@ -38,6 +38,8 @@ module Main
get "/blogroll/opml", to: "blogroll.opml"
get "/recently_played", to: "recently_played.index"
get "/recently_played_games", to: "recently_played_games.index"
get "/past_week", to: "past_week.index"
get "/:slug", to: "pages.show"

View File

@@ -0,0 +1,16 @@
require "steam-api"
module Main
module Queries
module Posts
class RecentGames
include Deps["settings"]
def call
Steam.apikey = settings.steam_api_key
Steam::Player.recently_played_games(settings.steam_user_id).fetch("games", []).take(2)
end
end
end
end
end

View File

@@ -0,0 +1,3 @@
div class="bg-lime-100 rounded dark:bg-lime-900 dark:text-gray-100 content-justify hover:bg-lime-200 hover:dark:bg-lime-800 decoration-wavy rounded py-1.5 px-2"
= "Latest week post: "
a href="#{past_week.permalink}" #{past_week.name}

View File

@@ -0,0 +1,8 @@
table
- recently_played_games.each do |game|
tr
td
= game[:name]
td
= "(#{game[:playtime_forever]}hrs)"

View File

@@ -0,0 +1,17 @@
module Main
module Views
module PastWeek
class Index < Main::View
config.layout = false
include Deps["repos.post_repo"]
expose :past_week do
post_repo.week_posts(limit: 1).to_a.map do |post|
Decorators::Posts::Decorator.new(post)
end.first
end
end
end
end
end

View File

@@ -0,0 +1,25 @@
module Main
module Views
module RecentlyPlayedGames
class Index < Main::View
config.layout = false
include Deps["queries.posts.recent_games"]
expose :recently_played_games do |recently_played_result|
# raise recently_played_result["data"].inspect
recently_played_result.map do |game|
{
name: game["name"],
playtime_forever: game["playtime_forever"].to_i / 60,
}
end
end
private_expose :recently_played_result do
recent_games.call
end
end
end
end
end