| 1 | package gallery |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "html/template" |
| 6 | ) |
| 7 | |
| 8 | // The Overview: the address every visitor lands on first. Its intro; |
| 9 | // then the demo application, framed, because what a first-time reader |
| 10 | // wants to know is what an app built with this looks like; then a |
| 11 | // route into each of the other pages, read off pageKinds() with each |
| 12 | // row's own blurb, so a page kind appears here the day its row lands. |
| 13 | const overviewBody = `{{define "ds-body-overview"}}<p class="ds-intro">{{say "gallery.overview.intro"}}</p> |
| 14 | <section class="ds-demo" id="demo-app"> |
| 15 | <h2 class="ds-sub">{{say "gallery.demo.heading"}}</h2> |
| 16 | <p class="ds-lead">{{say "gallery.demo.lead"}}</p> |
| 17 | {{template "ds-view" .Demo}} |
| 18 | <p class="ds-note"><a data-gallery-nav href="{{.DemoHref}}" target="_blank" rel="noopener">{{say "gallery.demo.open"}}<span class="rst-sr-only"> ({{say "gallery.newtab"}})</span></a>.</p> |
| 19 | </section> |
| 20 | <h2 class="ds-sub">{{say "gallery.overview.next"}}</h2> |
| 21 | <ul class="ds-routes">{{range .Routes}} |
| 22 | <li><a data-gallery-nav href="{{.Href}}">{{.Label}}</a><span>{{.Blurb}}</span></li>{{end}} |
| 23 | </ul> |
| 24 | {{end}}` |
| 25 | |
| 26 | // overviewBody renders the Overview's body for p: the page, with the |
| 27 | // demo's widget and address beside it. |
| 28 | func (s *site) overviewBody(p page) (template.HTML, error) { |
| 29 | return s.body(p.Locale, "ds-body-overview", struct { |
| 30 | page |
| 31 | Demo previewView |
| 32 | DemoHref string |
| 33 | }{p, s.demoView(p), s.demoHref(p.Theme, p.Locale)}) |
| 34 | } |
| 35 | |
| 36 | // body executes one named body template against data. |
| 37 | func (s *site) body(locale, name string, data any) (template.HTML, error) { |
| 38 | t, err := s.templates(locale) |
| 39 | if err != nil { |
| 40 | return "", err |
| 41 | } |
| 42 | var b bytes.Buffer |
| 43 | if err := t.ExecuteTemplate(&b, name, data); err != nil { |
| 44 | return "", err |
| 45 | } |
| 46 | return template.HTML(b.String()), nil |
| 47 | } |
| 48 | |
| 49 | func init() { registerTemplate(overviewBody) } |
| 50 | |