From 38acf4a904877fa6a65564a799396bb77b411e20 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sat, 14 Oct 2023 17:39:57 +0300 Subject: [PATCH] Testing jam embed --- src/templates/src/jam_2023_wrj_index.html | 6 ++++++ src/website/jam.go | 24 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/templates/src/jam_2023_wrj_index.html b/src/templates/src/jam_2023_wrj_index.html index 2c3759b..3b30e5d 100644 --- a/src/templates/src/jam_2023_wrj_index.html +++ b/src/templates/src/jam_2023_wrj_index.html @@ -18,6 +18,12 @@ } + {{ if .TwitchEmbedUrl }} +
+ +
+ {{ end }} +

Wheel Reinvention Jam

diff --git a/src/website/jam.go b/src/website/jam.go index 6092985..bbc6d24 100644 --- a/src/website/jam.go +++ b/src/website/jam.go @@ -1,12 +1,16 @@ package website import ( + "fmt" "net/http" + "net/url" "time" + "git.handmade.network/hmn/hmn/src/config" "git.handmade.network/hmn/hmn/src/db" "git.handmade.network/hmn/hmn/src/hmndata" "git.handmade.network/hmn/hmn/src/hmnurl" + "git.handmade.network/hmn/hmn/src/models" "git.handmade.network/hmn/hmn/src/oops" "git.handmade.network/hmn/hmn/src/templates" "git.handmade.network/hmn/hmn/src/utils" @@ -61,6 +65,7 @@ func JamIndex2023(c *RequestContext) ResponseData { ProjectSubmissionUrl string ShowcaseFeedUrl string ShowcaseJson string + TwitchEmbedUrl string JamProjects []templates.Project } @@ -119,6 +124,24 @@ func JamIndex2023(c *RequestContext) ResponseData { showcaseJson := templates.TimelineItemsToJSON(showcaseItems) + twitchEmbedUrl := "" + twitchStatus, err := db.QueryOne[models.TwitchLatestStatus](c, c.Conn, + ` + SELECT $columns + FROM twitch_latest_status + WHERE twitch_login = $1 + `, + "piratesoftware", + ) + if err == nil { + if twitchStatus.Live { + hmnUrl, err := url.Parse(config.Config.BaseUrl) + if err == nil { + twitchEmbedUrl = fmt.Sprintf("https://player.twitch.tv/?channel=%s&parent=%s", twitchStatus.TwitchLogin, hmnUrl.Hostname()) + } + } + } + res.MustWriteTemplate("jam_2023_wrj_index.html", JamPageData{ BaseData: baseData, DaysUntilStart: daysUntilStart, @@ -130,6 +153,7 @@ func JamIndex2023(c *RequestContext) ResponseData { ShowcaseFeedUrl: hmnurl.BuildJamFeed2023(), ShowcaseJson: showcaseJson, JamProjects: pageProjects, + TwitchEmbedUrl: twitchEmbedUrl, }, c.Perf) return res }