Add more endpoints for now page
This commit is contained in:
15
slices/main/actions/past_week/index.rb
Normal file
15
slices/main/actions/past_week/index.rb
Normal 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
|
15
slices/main/actions/recently_played_games/index.rb
Normal file
15
slices/main/actions/recently_played_games/index.rb
Normal 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
|
@@ -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"
|
||||
|
||||
|
16
slices/main/queries/posts/recent_games.rb
Normal file
16
slices/main/queries/posts/recent_games.rb
Normal 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
|
3
slices/main/templates/past_week/index.html.slim
Normal file
3
slices/main/templates/past_week/index.html.slim
Normal 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}
|
@@ -0,0 +1,8 @@
|
||||
table
|
||||
- recently_played_games.each do |game|
|
||||
tr
|
||||
td
|
||||
= game[:name]
|
||||
|
||||
td
|
||||
= "(#{game[:playtime_forever]}hrs)"
|
17
slices/main/views/past_week/index.rb
Normal file
17
slices/main/views/past_week/index.rb
Normal 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
|
25
slices/main/views/recently_played_games/index.rb
Normal file
25
slices/main/views/recently_played_games/index.rb
Normal 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
|
Reference in New Issue
Block a user