I get told to shut up a lot by my friend. This is the microsite that documents this in detail. shutup.jp
postcards microsite
at main 78 lines 1.7 kB view raw
1package main 2 3import ( 4 _ "embed" 5 ht "html/template" 6 "strings" 7 tt "text/template" 8 "time" 9 10 "github.com/gohugoio/hugo/tpl" 11 "github.com/jphastings/dotpostcard/formats" 12 "github.com/jphastings/dotpostcard/types" 13 "github.com/jphastings/shutup.jp/build/mapping" 14) 15 16func now() time.Time { 17 return time.Now() 18} 19 20func lastPC(pcs []types.Postcard) types.Postcard { 21 return pcs[len(pcs)-1] 22} 23 24func htmlEscape(str string) string { 25 return tt.HTMLEscapeString(str) 26} 27 28func plainify(str string) string { 29 return strings.TrimSpace(tpl.StripHTML(str)) 30} 31 32func altText(meta types.Metadata) string { 33 alt, _ := formats.AltText(meta, "en") 34 return alt 35} 36 37func annotate(at types.AnnotatedText) ht.HTML { 38 return ht.HTML(at.HTML()) 39} 40 41//go:embed world.svg 42var worldMapSVG string 43 44func worldMap(cs mapping.Countries, pcs []types.Postcard) ht.HTML { 45 collectedMap := worldMapSVG 46 47 for _, cc := range cs.Codes() { 48 collectedMap = strings.ReplaceAll(collectedMap, `id='`+cc+`'`, `id='`+cc+`' class='collected'`) 49 } 50 51 var allPoints string 52 for _, pc := range pcs { 53 x, y := ProjectRobinson(*pc.Meta.Location.Latitude, *pc.Meta.Location.Longitude) 54 allPoints += svgPointer(x, y, pc.Meta.Location.CountryCode) 55 } 56 57 collectedMap = strings.Replace(collectedMap, "id='points'>", "id='points'>"+allPoints, 1) 58 59 return ht.HTML(collectedMap) 60} 61 62var funcs = ht.FuncMap{ 63 "htmlEscape": htmlEscape, 64 "lastPC": lastPC, 65 "now": now, 66 "plainify": plainify, 67 "altText": altText, 68 "annotate": annotate, 69 "worldMap": worldMap, 70} 71 72//go:embed index.html.tmpl 73var indexStr string 74var indexTmpl = ht.Must(ht.New("index").Funcs(funcs).Parse(indexStr)) 75 76//go:embed feed.xml.tmpl 77var feedStr string 78var feedTmpl = tt.Must(tt.New("feed").Funcs(funcs).Parse(feedStr))