summaryrefslogtreecommitdiff
path: root/internal/generator/templates/embed.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/generator/templates/embed.go')
-rw-r--r--internal/generator/templates/embed.go65
1 files changed, 44 insertions, 21 deletions
diff --git a/internal/generator/templates/embed.go b/internal/generator/templates/embed.go
index 91ba07f..ac3efbd 100644
--- a/internal/generator/templates/embed.go
+++ b/internal/generator/templates/embed.go
@@ -1,8 +1,8 @@
-// Package templates exposes the embedded HTML theme and shared sub-templates
-// used by the generator. Themes and nav/HTML fragments live as separate files
-// under templates/themes/*.tmpl and templates/shared/*.tmpl so they can be
-// edited without recompiling logic; they are compiled into the binary via
-// //go:embed so snonux still ships as a single self-contained executable.
+// Package templates exposes the embedded HTML shell, shared CSS/JS bundles,
+// and per-theme assets used by the generator. Themes live as directories
+// under templates/themes/<name>/ containing theme.css, theme.js, and meta.json.
+// All assets are compiled into the binary via //go:embed so snonux still ships
+// as a single self-contained executable.
package templates
import (
@@ -11,24 +11,24 @@ import (
"io/fs"
"path"
"sort"
- "strings"
)
-//go:embed themes/*.tmpl shared/*.tmpl
+//go:embed shell.tmpl shared/*.tmpl shared/shared.css shared/shared.js themes/*/theme.css themes/*/theme.js themes/*/meta.json
var FS embed.FS
-// Theme reads the raw HTML template body for a named theme.
-// The returned string is the outer page template; shared sub-templates
-// (navhints, navmodal, navscript, etc.) are obtained via Shared().
-func Theme(name string) (string, error) {
- b, err := FS.ReadFile(path.Join("themes", name+".tmpl"))
+// Shell returns the body of shell.tmpl — the single page template used for
+// every generated HTML page. Theme-specific markup is injected at gen time
+// from the default theme's meta.json (and at runtime by shared.js for any
+// other selected theme).
+func Shell() (string, error) {
+ b, err := FS.ReadFile("shell.tmpl")
if err != nil {
- return "", fmt.Errorf("read theme %q: %w", name, err)
+ return "", fmt.Errorf("read shell.tmpl: %w", err)
}
return string(b), nil
}
-// Shared reads a named shared sub-template file from shared/*.tmpl.
+// Shared reads a named shared sub-template (currently only "nav").
func Shared(name string) (string, error) {
b, err := FS.ReadFile(path.Join("shared", name+".tmpl"))
if err != nil {
@@ -37,8 +37,35 @@ func Shared(name string) (string, error) {
return string(b), nil
}
+// SharedCSS returns the bundled CSS that every page links via shared.css.
+// Used by the generator to write dist/shared.css.
+func SharedCSS() ([]byte, error) {
+ return FS.ReadFile("shared/shared.css")
+}
+
+// SharedJS returns the bundled JS that every page references via shared.js.
+// Used by the generator to write dist/shared.js.
+func SharedJS() ([]byte, error) {
+ return FS.ReadFile("shared/shared.js")
+}
+
+// ThemeCSS returns the per-theme stylesheet bytes for the named theme.
+func ThemeCSS(name string) ([]byte, error) {
+ return FS.ReadFile(path.Join("themes", name, "theme.css"))
+}
+
+// ThemeJS returns the per-theme script bytes for the named theme.
+func ThemeJS(name string) ([]byte, error) {
+ return FS.ReadFile(path.Join("themes", name, "theme.js"))
+}
+
+// ThemeMeta returns the per-theme meta.json bytes for the named theme.
+func ThemeMeta(name string) ([]byte, error) {
+ return FS.ReadFile(path.Join("themes", name, "meta.json"))
+}
+
// ThemeNames returns a sorted list of available theme names derived from the
-// files present under templates/themes/.
+// directories present under templates/themes/.
func ThemeNames() ([]string, error) {
entries, err := fs.ReadDir(FS, "themes")
if err != nil {
@@ -47,14 +74,10 @@ func ThemeNames() ([]string, error) {
names := make([]string, 0, len(entries))
for _, e := range entries {
- if e.IsDir() {
- continue
- }
- n := e.Name()
- if !strings.HasSuffix(n, ".tmpl") {
+ if !e.IsDir() {
continue
}
- names = append(names, strings.TrimSuffix(n, ".tmpl"))
+ names = append(names, e.Name())
}
sort.Strings(names)