Add banner and maybe other things, I do not remember
This commit is contained in:
parent
bcc27b06d9
commit
c49a5e0bb3
|
@ -12,6 +12,7 @@ import (
|
||||||
"git.handmade.network/hmn/hmn/src/hmnurl"
|
"git.handmade.network/hmn/hmn/src/hmnurl"
|
||||||
"git.handmade.network/hmn/hmn/src/links"
|
"git.handmade.network/hmn/hmn/src/links"
|
||||||
"git.handmade.network/hmn/hmn/src/models"
|
"git.handmade.network/hmn/hmn/src/models"
|
||||||
|
"git.handmade.network/hmn/hmn/src/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PostToTemplate(p *models.Post, author *models.User) Post {
|
func PostToTemplate(p *models.Post, author *models.User) Post {
|
||||||
|
@ -494,6 +495,17 @@ func CalendarEventToTemplate(ev *calendar.CalendarEvent) CalendarEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JamToBannerEvent(jam hmndata.Jam) BannerEvent {
|
||||||
|
return BannerEvent{
|
||||||
|
Slug: jam.Slug,
|
||||||
|
DaysUntilStart: utils.DaysUntil(jam.StartTime),
|
||||||
|
DaysUntilEnd: utils.DaysUntil(jam.EndTime),
|
||||||
|
StartTimeUnix: jam.StartTime.Unix(),
|
||||||
|
EndTimeUnix: jam.EndTime.Unix(),
|
||||||
|
Url: hmnurl.BuildJamIndexAny(jam.UrlSlug),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func maybeString(s *string) string {
|
func maybeString(s *string) string {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -56,6 +56,32 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
{{ if and .Header.BannerEvent (not .Header.SuppressBanners) }}
|
||||||
|
{{ with .Header.BannerEvent }}
|
||||||
|
{{ if eq .Slug "VJ2024" }}
|
||||||
|
<a
|
||||||
|
class="db tc pv2 link-normal c-white"
|
||||||
|
style="background: linear-gradient(to bottom right, #20dddd, #007178)"
|
||||||
|
href="{{ .Url }}"
|
||||||
|
>
|
||||||
|
<b>Visibility Jam.</b>
|
||||||
|
July 19-21, 2024.
|
||||||
|
{{ if gt .DaysUntilEnd 0 }}
|
||||||
|
{{ if eq .DaysUntilStart 0 }}
|
||||||
|
<b>Happening now.</b>
|
||||||
|
{{ else if eq .DaysUntilStart 1 }}
|
||||||
|
<b>Starting tomorrow.</b>
|
||||||
|
{{ else }}
|
||||||
|
<b>In {{ .DaysUntilStart }} days.</b>
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
<b>See the results.</b>
|
||||||
|
{{ end }}
|
||||||
|
</a>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
const header = document.querySelector('#site-header');
|
const header = document.querySelector('#site-header');
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
{{ block "content-top" . }}{{ end }}
|
{{ block "content-top" . }}{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<!-- TODO: Notices -->
|
<!-- TODO: Notices -->
|
||||||
<div class="c-white flex-grow-1">
|
<div class="flex-grow-1">
|
||||||
{{ block "content" . }}{{ end }}
|
{{ block "content" . }}{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ template "footer-2024.html" . }}
|
{{ template "footer-2024.html" . }}
|
||||||
|
|
|
@ -60,6 +60,17 @@ type Header struct {
|
||||||
AboutUrl string
|
AboutUrl string
|
||||||
|
|
||||||
Project *ProjectHeader
|
Project *ProjectHeader
|
||||||
|
|
||||||
|
BannerEvent *BannerEvent
|
||||||
|
SuppressBanners bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type BannerEvent struct {
|
||||||
|
Slug string
|
||||||
|
Url string
|
||||||
|
|
||||||
|
DaysUntilStart, DaysUntilEnd int
|
||||||
|
StartTimeUnix, EndTimeUnix int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProjectHeader struct {
|
type ProjectHeader struct {
|
||||||
|
|
|
@ -68,6 +68,14 @@ func NumPages(numThings, thingsPerPage int) int {
|
||||||
return Max(int(math.Ceil(float64(numThings)/float64(thingsPerPage))), 1)
|
return Max(int(math.Ceil(float64(numThings)/float64(thingsPerPage))), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DaysUntil(t time.Time) int {
|
||||||
|
d := t.Sub(time.Now())
|
||||||
|
if d < 0 {
|
||||||
|
d = 0
|
||||||
|
}
|
||||||
|
return int(DurationRoundUp(d, 24*time.Hour) / (24 * time.Hour))
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Recover a panic and convert it to a returned error. Call it like so:
|
Recover a panic and convert it to a returned error. Call it like so:
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package website
|
package website
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.handmade.network/hmn/hmn/src/buildscss"
|
"git.handmade.network/hmn/hmn/src/buildscss"
|
||||||
"git.handmade.network/hmn/hmn/src/config"
|
"git.handmade.network/hmn/hmn/src/config"
|
||||||
|
"git.handmade.network/hmn/hmn/src/hmndata"
|
||||||
"git.handmade.network/hmn/hmn/src/hmnurl"
|
"git.handmade.network/hmn/hmn/src/hmnurl"
|
||||||
"git.handmade.network/hmn/hmn/src/models"
|
"git.handmade.network/hmn/hmn/src/models"
|
||||||
"git.handmade.network/hmn/hmn/src/templates"
|
"git.handmade.network/hmn/hmn/src/templates"
|
||||||
|
"git.handmade.network/hmn/hmn/src/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getBaseDataAutocrumb(c *RequestContext, title string) templates.BaseData {
|
func getBaseDataAutocrumb(c *RequestContext, title string) templates.BaseData {
|
||||||
|
@ -43,6 +47,19 @@ func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bannerEvent *templates.BannerEvent
|
||||||
|
for _, jam := range hmndata.AllJams {
|
||||||
|
graceBefore := (24 * time.Hour) * 30
|
||||||
|
graceAfter := (24 * time.Hour) * 14
|
||||||
|
|
||||||
|
afterStart := time.Now().After(jam.StartTime.Add(-graceBefore))
|
||||||
|
beforeEnd := time.Now().Before(jam.EndTime.Add(graceAfter))
|
||||||
|
|
||||||
|
if afterStart && beforeEnd {
|
||||||
|
bannerEvent = utils.P(templates.JamToBannerEvent(jam))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
baseData := templates.BaseData{
|
baseData := templates.BaseData{
|
||||||
Title: title,
|
Title: title,
|
||||||
Breadcrumbs: breadcrumbs,
|
Breadcrumbs: breadcrumbs,
|
||||||
|
@ -81,6 +98,8 @@ func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadc
|
||||||
CalendarUrl: hmnurl.BuildCalendarIndex(),
|
CalendarUrl: hmnurl.BuildCalendarIndex(),
|
||||||
ManifestoUrl: hmnurl.BuildManifesto(),
|
ManifestoUrl: hmnurl.BuildManifesto(),
|
||||||
AboutUrl: hmnurl.BuildAbout(),
|
AboutUrl: hmnurl.BuildAbout(),
|
||||||
|
|
||||||
|
BannerEvent: bannerEvent,
|
||||||
},
|
},
|
||||||
Footer: templates.Footer{
|
Footer: templates.Footer{
|
||||||
HomepageUrl: hmnurl.BuildHomepage(),
|
HomepageUrl: hmnurl.BuildHomepage(),
|
||||||
|
|
|
@ -110,6 +110,7 @@ func JamIndex2024_Visibility(c *RequestContext) ResponseData {
|
||||||
{Name: "twitter:image", Value: hmnurl.BuildPublic("visjam2024/TwitterCard.png", true)},
|
{Name: "twitter:image", Value: hmnurl.BuildPublic("visjam2024/TwitterCard.png", true)},
|
||||||
}
|
}
|
||||||
baseData.BodyClasses = append(baseData.BodyClasses, "header-transparent")
|
baseData.BodyClasses = append(baseData.BodyClasses, "header-transparent")
|
||||||
|
baseData.Header.SuppressBanners = true
|
||||||
|
|
||||||
type JamPageData struct {
|
type JamPageData struct {
|
||||||
templates.BaseData
|
templates.BaseData
|
||||||
|
@ -157,8 +158,8 @@ func getVJ2024BaseData(c *RequestContext) (JamBaseDataVJ2024, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return JamBaseDataVJ2024{
|
return JamBaseDataVJ2024{
|
||||||
DaysUntilStart: daysUntil(jam.StartTime),
|
DaysUntilStart: utils.DaysUntil(jam.StartTime),
|
||||||
DaysUntilEnd: daysUntil(jam.EndTime),
|
DaysUntilEnd: utils.DaysUntil(jam.EndTime),
|
||||||
StartTimeUnix: jam.StartTime.Unix(),
|
StartTimeUnix: jam.StartTime.Unix(),
|
||||||
EndTimeUnix: jam.EndTime.Unix(),
|
EndTimeUnix: jam.EndTime.Unix(),
|
||||||
|
|
||||||
|
@ -301,8 +302,8 @@ type JamFeedDataLJ2024 struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLJ2024BaseData(c *RequestContext) (JamBaseDataLJ2024, error) {
|
func getLJ2024BaseData(c *RequestContext) (JamBaseDataLJ2024, error) {
|
||||||
daysUntilStart := daysUntil(hmndata.LJ2024.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.LJ2024.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.LJ2024.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.LJ2024.EndTime)
|
||||||
|
|
||||||
tmpl := JamBaseDataLJ2024{
|
tmpl := JamBaseDataLJ2024{
|
||||||
UserAvatarUrl: templates.UserAvatarDefaultUrl("dark"),
|
UserAvatarUrl: templates.UserAvatarDefaultUrl("dark"),
|
||||||
|
@ -405,8 +406,8 @@ func getTwitchEmbedUrl(c *RequestContext) string {
|
||||||
func JamIndex2023(c *RequestContext) ResponseData {
|
func JamIndex2023(c *RequestContext) ResponseData {
|
||||||
var res ResponseData
|
var res ResponseData
|
||||||
|
|
||||||
daysUntilStart := daysUntil(hmndata.WRJ2023.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.WRJ2023.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.WRJ2023.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2023.EndTime)
|
||||||
|
|
||||||
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2023.Name)
|
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2023.Name)
|
||||||
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
||||||
|
@ -561,8 +562,8 @@ func JamFeed2023(c *RequestContext) ResponseData {
|
||||||
TimelineItems []templates.TimelineItem
|
TimelineItems []templates.TimelineItem
|
||||||
}
|
}
|
||||||
|
|
||||||
daysUntilStart := daysUntil(hmndata.WRJ2023.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.WRJ2023.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.WRJ2023.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2023.EndTime)
|
||||||
|
|
||||||
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2023.Name)
|
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2023.Name)
|
||||||
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
||||||
|
@ -587,8 +588,8 @@ func JamFeed2023(c *RequestContext) ResponseData {
|
||||||
func JamIndex2023_Visibility(c *RequestContext) ResponseData {
|
func JamIndex2023_Visibility(c *RequestContext) ResponseData {
|
||||||
var res ResponseData
|
var res ResponseData
|
||||||
|
|
||||||
daysUntilStart := daysUntil(hmndata.VJ2023.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.VJ2023.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.VJ2023.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.VJ2023.EndTime)
|
||||||
|
|
||||||
baseData := getBaseDataAutocrumb(c, hmndata.VJ2023.Name)
|
baseData := getBaseDataAutocrumb(c, hmndata.VJ2023.Name)
|
||||||
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
||||||
|
@ -729,8 +730,8 @@ func JamFeed2023_Visibility(c *RequestContext) ResponseData {
|
||||||
TimelineItems []templates.TimelineItem
|
TimelineItems []templates.TimelineItem
|
||||||
}
|
}
|
||||||
|
|
||||||
daysUntilStart := daysUntil(hmndata.VJ2023.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.VJ2023.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.VJ2023.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.VJ2023.EndTime)
|
||||||
|
|
||||||
baseData := getBaseDataAutocrumb(c, hmndata.VJ2023.Name)
|
baseData := getBaseDataAutocrumb(c, hmndata.VJ2023.Name)
|
||||||
|
|
||||||
|
@ -804,8 +805,8 @@ func JamRecap2023_Visibility(c *RequestContext) ResponseData {
|
||||||
func JamIndex2022(c *RequestContext) ResponseData {
|
func JamIndex2022(c *RequestContext) ResponseData {
|
||||||
var res ResponseData
|
var res ResponseData
|
||||||
|
|
||||||
daysUntilStart := daysUntil(hmndata.WRJ2022.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.WRJ2022.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.WRJ2022.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2022.EndTime)
|
||||||
|
|
||||||
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
|
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
|
||||||
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
||||||
|
@ -940,8 +941,8 @@ func JamFeed2022(c *RequestContext) ResponseData {
|
||||||
TimelineItems []templates.TimelineItem
|
TimelineItems []templates.TimelineItem
|
||||||
}
|
}
|
||||||
|
|
||||||
daysUntilStart := daysUntil(hmndata.WRJ2022.StartTime)
|
daysUntilStart := utils.DaysUntil(hmndata.WRJ2022.StartTime)
|
||||||
daysUntilEnd := daysUntil(hmndata.WRJ2022.EndTime)
|
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2022.EndTime)
|
||||||
|
|
||||||
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
|
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
|
||||||
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
baseData.OpenGraphItems = []templates.OpenGraphItem{
|
||||||
|
@ -966,7 +967,7 @@ func JamFeed2022(c *RequestContext) ResponseData {
|
||||||
func JamIndex2021(c *RequestContext) ResponseData {
|
func JamIndex2021(c *RequestContext) ResponseData {
|
||||||
var res ResponseData
|
var res ResponseData
|
||||||
|
|
||||||
daysUntilJam := daysUntil(hmndata.WRJ2021.StartTime)
|
daysUntilJam := utils.DaysUntil(hmndata.WRJ2021.StartTime)
|
||||||
if daysUntilJam < 0 {
|
if daysUntilJam < 0 {
|
||||||
daysUntilJam = 0
|
daysUntilJam = 0
|
||||||
}
|
}
|
||||||
|
@ -1022,11 +1023,3 @@ func JamIndex2021(c *RequestContext) ResponseData {
|
||||||
}, c.Perf)
|
}, c.Perf)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"git.handmade.network/hmn/hmn/src/models"
|
"git.handmade.network/hmn/hmn/src/models"
|
||||||
"git.handmade.network/hmn/hmn/src/oops"
|
"git.handmade.network/hmn/hmn/src/oops"
|
||||||
"git.handmade.network/hmn/hmn/src/templates"
|
"git.handmade.network/hmn/hmn/src/templates"
|
||||||
|
"git.handmade.network/hmn/hmn/src/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Index(c *RequestContext) ResponseData {
|
func Index(c *RequestContext) ResponseData {
|
||||||
|
@ -149,14 +150,14 @@ func Index(c *RequestContext) ResponseData {
|
||||||
NewProjectUrl: hmnurl.BuildProjectNew(),
|
NewProjectUrl: hmnurl.BuildProjectNew(),
|
||||||
|
|
||||||
JamUrl: hmnurl.BuildJamIndex2024_Learning(),
|
JamUrl: hmnurl.BuildJamIndex2024_Learning(),
|
||||||
JamDaysUntilStart: daysUntil(hmndata.LJ2024.StartTime),
|
JamDaysUntilStart: utils.DaysUntil(hmndata.LJ2024.StartTime),
|
||||||
JamDaysUntilEnd: daysUntil(hmndata.LJ2024.EndTime),
|
JamDaysUntilEnd: utils.DaysUntil(hmndata.LJ2024.EndTime),
|
||||||
|
|
||||||
HMSDaysUntilStart: daysUntil(hmndata.HMS2024.StartTime),
|
HMSDaysUntilStart: utils.DaysUntil(hmndata.HMS2024.StartTime),
|
||||||
HMSDaysUntilEnd: daysUntil(hmndata.HMS2024.EndTime),
|
HMSDaysUntilEnd: utils.DaysUntil(hmndata.HMS2024.EndTime),
|
||||||
|
|
||||||
HMBostonDaysUntilStart: daysUntil(hmndata.HMBoston2024.StartTime),
|
HMBostonDaysUntilStart: utils.DaysUntil(hmndata.HMBoston2024.StartTime),
|
||||||
HMBostonDaysUntilEnd: daysUntil(hmndata.HMBoston2024.EndTime),
|
HMBostonDaysUntilEnd: utils.DaysUntil(hmndata.HMBoston2024.EndTime),
|
||||||
}, c.Perf)
|
}, c.Perf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to render landing page template"))
|
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to render landing page template"))
|
||||||
|
|
Reference in New Issue