hmn/src/website/jam.go

120 lines
3.6 KiB
Go
Raw Normal View History

2021-08-28 11:26:17 +00:00
package website
import (
2021-09-25 03:53:00 +00:00
"net/http"
"time"
"git.handmade.network/hmn/hmn/src/hmndata"
2021-08-28 11:26:17 +00:00
"git.handmade.network/hmn/hmn/src/hmnurl"
2021-09-25 03:53:00 +00:00
"git.handmade.network/hmn/hmn/src/oops"
2021-08-28 11:26:17 +00:00
"git.handmade.network/hmn/hmn/src/templates"
2022-06-17 22:30:18 +00:00
"git.handmade.network/hmn/hmn/src/utils"
2021-08-28 11:26:17 +00:00
)
2022-06-17 22:30:18 +00:00
func JamIndex2022(c *RequestContext) ResponseData {
var res ResponseData
2022-06-19 22:26:33 +00:00
// If logged in, fetch jam project
// Link to project page if found, otherwise link to project creation page with ?jam=1
2022-06-17 22:30:18 +00:00
2022-06-19 22:26:33 +00:00
daysUntilStart := daysUntil(hmndata.WRJ2022.StartTime)
daysUntilEnd := daysUntil(hmndata.WRJ2022.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
2022-06-17 22:30:18 +00:00
baseData.OpenGraphItems = []templates.OpenGraphItem{
{Property: "og:site_name", Value: "Handmade.Network"},
{Property: "og:type", Value: "website"},
{Property: "og:image", Value: hmnurl.BuildPublic("wheeljam2022/opengraph.png", true)},
{Property: "og:description", Value: "A one-week jam to change the status quo. August 15 - 21 on Handmade Network."},
2022-06-17 22:30:18 +00:00
{Property: "og:url", Value: hmnurl.BuildJamIndex()},
}
type JamPageData struct {
templates.BaseData
DaysUntilStart, DaysUntilEnd int
}
res.MustWriteTemplate("wheeljam_2022_index.html", JamPageData{
BaseData: baseData,
DaysUntilStart: daysUntilStart,
DaysUntilEnd: daysUntilEnd,
}, c.Perf)
return res
}
2022-06-19 22:26:33 +00:00
func JamFeed2022(c *RequestContext) ResponseData {
// List newly-created jam projects
// list snippets from jam projects
// list forum posts from jam project threads
// timeline everything
return FourOhFour(c)
}
2022-06-17 22:30:18 +00:00
func JamIndex2021(c *RequestContext) ResponseData {
2021-08-28 11:26:17 +00:00
var res ResponseData
2022-06-19 22:26:33 +00:00
daysUntilJam := daysUntil(hmndata.WRJ2021.StartTime)
2022-06-17 22:30:18 +00:00
if daysUntilJam < 0 {
daysUntilJam = 0
}
2021-08-28 11:26:17 +00:00
tagId := -1
jamTag, err := hmndata.FetchTag(c.Context(), c.Conn, hmndata.TagQuery{
Text: []string{"wheeljam"},
})
2021-11-11 19:00:46 +00:00
if err == nil {
tagId = jamTag.ID
2021-11-11 19:00:46 +00:00
} else {
c.Logger.Warn().Err(err).Msg("failed to fetch jam tag; will fetch all snippets as a result")
2021-09-25 03:53:00 +00:00
}
2021-11-11 19:00:46 +00:00
snippets, err := hmndata.FetchSnippets(c.Context(), c.Conn, c.CurrentUser, hmndata.SnippetQuery{
Tags: []int{tagId},
2021-11-11 19:00:46 +00:00
})
2021-09-25 03:53:00 +00:00
if err != nil {
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch jam snippets"))
}
2021-11-11 19:00:46 +00:00
showcaseItems := make([]templates.TimelineItem, 0, len(snippets))
for _, s := range snippets {
timelineItem := SnippetToTimelineItem(&s.Snippet, s.Asset, s.DiscordMessage, s.Tags, s.Owner, c.Theme)
if timelineItem.CanShowcase {
2021-09-25 03:53:00 +00:00
showcaseItems = append(showcaseItems, timelineItem)
}
}
c.Perf.EndBlock()
c.Perf.StartBlock("SHOWCASE", "Convert to json")
showcaseJson := templates.TimelineItemsToJSON(showcaseItems)
c.Perf.EndBlock()
2022-06-19 22:26:33 +00:00
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2021.Name)
2021-08-28 11:26:17 +00:00
baseData.OpenGraphItems = []templates.OpenGraphItem{
{Property: "og:site_name", Value: "Handmade.Network"},
{Property: "og:type", Value: "website"},
{Property: "og:image", Value: hmnurl.BuildPublic("wheeljam2021/opengraph.png", true)},
2021-08-28 11:26:17 +00:00
{Property: "og:description", Value: "A one-week jam to bring a fresh perspective to old ideas. September 27 - October 3 on Handmade Network."},
{Property: "og:url", Value: hmnurl.BuildJamIndex()},
}
type JamPageData struct {
templates.BaseData
2021-09-25 03:53:00 +00:00
DaysUntil int
ShowcaseItemsJSON string
}
2022-06-17 22:30:18 +00:00
res.MustWriteTemplate("wheeljam_2021_index.html", JamPageData{
2021-09-25 03:53:00 +00:00
BaseData: baseData,
2022-06-17 22:30:18 +00:00
DaysUntil: daysUntilJam,
2021-09-25 03:53:00 +00:00
ShowcaseItemsJSON: showcaseJson,
}, c.Perf)
2021-08-28 11:26:17 +00:00
return res
}
2022-06-17 22:30:18 +00:00
func daysUntil(t time.Time) int {
d := t.Sub(time.Now())
if d < 0 {
d = 0
}
return int(utils.DurationRoundUp(d, 24*time.Hour) / (24 * time.Hour))
}