Add banner and maybe other things, I do not remember

This commit is contained in:
Ben Visness 2024-07-04 17:26:36 -05:00
parent bcc27b06d9
commit c49a5e0bb3
8 changed files with 102 additions and 32 deletions

View File

@ -12,6 +12,7 @@ import (
"git.handmade.network/hmn/hmn/src/hmnurl"
"git.handmade.network/hmn/hmn/src/links"
"git.handmade.network/hmn/hmn/src/models"
"git.handmade.network/hmn/hmn/src/utils"
)
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 {
if s == nil {
return ""

View File

@ -56,6 +56,32 @@
{{ end }}
</div>
</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">
document.addEventListener("DOMContentLoaded", function() {
const header = document.querySelector('#site-header');

View File

@ -66,7 +66,7 @@
{{ block "content-top" . }}{{ end }}
</div>
<!-- TODO: Notices -->
<div class="c-white flex-grow-1">
<div class="flex-grow-1">
{{ block "content" . }}{{ end }}
</div>
{{ template "footer-2024.html" . }}

View File

@ -60,6 +60,17 @@ type Header struct {
AboutUrl string
Project *ProjectHeader
BannerEvent *BannerEvent
SuppressBanners bool
}
type BannerEvent struct {
Slug string
Url string
DaysUntilStart, DaysUntilEnd int
StartTimeUnix, EndTimeUnix int64
}
type ProjectHeader struct {

View File

@ -68,6 +68,14 @@ func NumPages(numThings, thingsPerPage int) int {
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:

View File

@ -1,11 +1,15 @@
package website
import (
"time"
"git.handmade.network/hmn/hmn/src/buildscss"
"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/models"
"git.handmade.network/hmn/hmn/src/templates"
"git.handmade.network/hmn/hmn/src/utils"
)
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{
Title: title,
Breadcrumbs: breadcrumbs,
@ -81,6 +98,8 @@ func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadc
CalendarUrl: hmnurl.BuildCalendarIndex(),
ManifestoUrl: hmnurl.BuildManifesto(),
AboutUrl: hmnurl.BuildAbout(),
BannerEvent: bannerEvent,
},
Footer: templates.Footer{
HomepageUrl: hmnurl.BuildHomepage(),

View File

@ -110,6 +110,7 @@ func JamIndex2024_Visibility(c *RequestContext) ResponseData {
{Name: "twitter:image", Value: hmnurl.BuildPublic("visjam2024/TwitterCard.png", true)},
}
baseData.BodyClasses = append(baseData.BodyClasses, "header-transparent")
baseData.Header.SuppressBanners = true
type JamPageData struct {
templates.BaseData
@ -157,8 +158,8 @@ func getVJ2024BaseData(c *RequestContext) (JamBaseDataVJ2024, error) {
}
return JamBaseDataVJ2024{
DaysUntilStart: daysUntil(jam.StartTime),
DaysUntilEnd: daysUntil(jam.EndTime),
DaysUntilStart: utils.DaysUntil(jam.StartTime),
DaysUntilEnd: utils.DaysUntil(jam.EndTime),
StartTimeUnix: jam.StartTime.Unix(),
EndTimeUnix: jam.EndTime.Unix(),
@ -301,8 +302,8 @@ type JamFeedDataLJ2024 struct {
}
func getLJ2024BaseData(c *RequestContext) (JamBaseDataLJ2024, error) {
daysUntilStart := daysUntil(hmndata.LJ2024.StartTime)
daysUntilEnd := daysUntil(hmndata.LJ2024.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.LJ2024.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.LJ2024.EndTime)
tmpl := JamBaseDataLJ2024{
UserAvatarUrl: templates.UserAvatarDefaultUrl("dark"),
@ -405,8 +406,8 @@ func getTwitchEmbedUrl(c *RequestContext) string {
func JamIndex2023(c *RequestContext) ResponseData {
var res ResponseData
daysUntilStart := daysUntil(hmndata.WRJ2023.StartTime)
daysUntilEnd := daysUntil(hmndata.WRJ2023.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.WRJ2023.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2023.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2023.Name)
baseData.OpenGraphItems = []templates.OpenGraphItem{
@ -561,8 +562,8 @@ func JamFeed2023(c *RequestContext) ResponseData {
TimelineItems []templates.TimelineItem
}
daysUntilStart := daysUntil(hmndata.WRJ2023.StartTime)
daysUntilEnd := daysUntil(hmndata.WRJ2023.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.WRJ2023.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2023.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2023.Name)
baseData.OpenGraphItems = []templates.OpenGraphItem{
@ -587,8 +588,8 @@ func JamFeed2023(c *RequestContext) ResponseData {
func JamIndex2023_Visibility(c *RequestContext) ResponseData {
var res ResponseData
daysUntilStart := daysUntil(hmndata.VJ2023.StartTime)
daysUntilEnd := daysUntil(hmndata.VJ2023.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.VJ2023.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.VJ2023.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.VJ2023.Name)
baseData.OpenGraphItems = []templates.OpenGraphItem{
@ -729,8 +730,8 @@ func JamFeed2023_Visibility(c *RequestContext) ResponseData {
TimelineItems []templates.TimelineItem
}
daysUntilStart := daysUntil(hmndata.VJ2023.StartTime)
daysUntilEnd := daysUntil(hmndata.VJ2023.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.VJ2023.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.VJ2023.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.VJ2023.Name)
@ -804,8 +805,8 @@ func JamRecap2023_Visibility(c *RequestContext) ResponseData {
func JamIndex2022(c *RequestContext) ResponseData {
var res ResponseData
daysUntilStart := daysUntil(hmndata.WRJ2022.StartTime)
daysUntilEnd := daysUntil(hmndata.WRJ2022.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.WRJ2022.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2022.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
baseData.OpenGraphItems = []templates.OpenGraphItem{
@ -940,8 +941,8 @@ func JamFeed2022(c *RequestContext) ResponseData {
TimelineItems []templates.TimelineItem
}
daysUntilStart := daysUntil(hmndata.WRJ2022.StartTime)
daysUntilEnd := daysUntil(hmndata.WRJ2022.EndTime)
daysUntilStart := utils.DaysUntil(hmndata.WRJ2022.StartTime)
daysUntilEnd := utils.DaysUntil(hmndata.WRJ2022.EndTime)
baseData := getBaseDataAutocrumb(c, hmndata.WRJ2022.Name)
baseData.OpenGraphItems = []templates.OpenGraphItem{
@ -966,7 +967,7 @@ func JamFeed2022(c *RequestContext) ResponseData {
func JamIndex2021(c *RequestContext) ResponseData {
var res ResponseData
daysUntilJam := daysUntil(hmndata.WRJ2021.StartTime)
daysUntilJam := utils.DaysUntil(hmndata.WRJ2021.StartTime)
if daysUntilJam < 0 {
daysUntilJam = 0
}
@ -1022,11 +1023,3 @@ func JamIndex2021(c *RequestContext) ResponseData {
}, c.Perf)
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))
}

View File

@ -9,6 +9,7 @@ import (
"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"
)
func Index(c *RequestContext) ResponseData {
@ -149,14 +150,14 @@ func Index(c *RequestContext) ResponseData {
NewProjectUrl: hmnurl.BuildProjectNew(),
JamUrl: hmnurl.BuildJamIndex2024_Learning(),
JamDaysUntilStart: daysUntil(hmndata.LJ2024.StartTime),
JamDaysUntilEnd: daysUntil(hmndata.LJ2024.EndTime),
JamDaysUntilStart: utils.DaysUntil(hmndata.LJ2024.StartTime),
JamDaysUntilEnd: utils.DaysUntil(hmndata.LJ2024.EndTime),
HMSDaysUntilStart: daysUntil(hmndata.HMS2024.StartTime),
HMSDaysUntilEnd: daysUntil(hmndata.HMS2024.EndTime),
HMSDaysUntilStart: utils.DaysUntil(hmndata.HMS2024.StartTime),
HMSDaysUntilEnd: utils.DaysUntil(hmndata.HMS2024.EndTime),
HMBostonDaysUntilStart: daysUntil(hmndata.HMBoston2024.StartTime),
HMBostonDaysUntilEnd: daysUntil(hmndata.HMBoston2024.EndTime),
HMBostonDaysUntilStart: utils.DaysUntil(hmndata.HMBoston2024.StartTime),
HMBostonDaysUntilEnd: utils.DaysUntil(hmndata.HMBoston2024.EndTime),
}, c.Perf)
if err != nil {
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to render landing page template"))