summaryrefslogtreecommitdiff
path: root/internal/generator/shared.go
blob: 378a01f2aed0ebc5f0b2c75e8fe9958c022ef922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package generator

import (
	"log"
	"sync"

	"codeberg.org/snonux/snonux/internal/generator/templates"
)

// navDefs is the content of templates/shared/nav.tmpl loaded once at startup.
// It defines named sub-templates shared across all themes:
//   - "splashGate" — synchronous script: first child of <body>; sets html.sno-splash-skip when
//     splash should not run (?splash=0, not index path, or Referer from same-site index/pageN).
//   - "navhints"  — keyboard shortcut hint bar HTML
//   - "navSharedCSSInner" — shared CSS (injected inside each theme's <style> in <head>)
//   - "navmodal"  — full-screen expanded-post modal HTML (no <style>; CSS lives in head)
//   - "navscript" — keyboard navigation + Web Audio; splash/nav/modal sounds from themeSoundsJSON (per theme)
//
// Each theme ends its <style> with {{template "navSharedCSSInner"}} then calls
// {{template "splashGate"}}, {{template "navhints" .}}, {{template "navmodal" .}},
// and {{template "navscript" .}} at the appropriate points in its HTML.
var (
	navDefsCache string
	navDefsOnce  sync.Once
)

func getNavDefs() string {
	navDefsOnce.Do(func() {
		s, err := templates.Shared("nav")
		if err != nil {
			log.Printf("warning: could not load shared nav template: %v", err)
			return
		}
		navDefsCache = s
	})
	return navDefsCache
}