theme

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package theme resolves, lists and loads goblog themes. A theme is a directory with templates/ (and optionally static/). Built-in themes ship in the image under themes/; themes installed from the directory live in a separate, persisted root so a Docker bind mount can keep them across redeploys without hiding the built-ins.

Index

Constants

View Source
const DefaultName = "default"

DefaultName is the theme every other theme is layered on.

View Source
const MaxTemplateBytes = 256 << 10

MaxTemplateBytes caps one template file before it is parsed. The parser recurses once per nested {{if}}/{{with}}/{{range}}, so an unbounded file can exhaust the stack (a fatal error, not a panic); goblog's largest real template is under 32 KiB.

Variables

View Source
var (
	BuiltinRoot = "themes"
	SharedDir   = "templates/shared"
)

BuiltinRoot holds the themes compiled into the image (and, on bare metal, whatever the operator drops there). SharedDir holds the templates every theme gets. Both are package variables so tests can point them at temp dirs.

Functions

func Dir

func Dir(name string) (string, bool)

Dir returns the directory of a theme — the built-in one first, then the installed one — and whether it exists. A directory counts only when it has a templates/ subdirectory.

func FuncMap

func FuncMap() template.FuncMap

FuncMap is the template.FuncMap every theme is loaded with.

func InstalledRoot

func InstalledRoot() string

InstalledRoot is where the theme installer writes: $THEMES_INSTALLED_DIR, or themes/installed (under the data directory when one is set). Read on every call so tests can change it.

func IsBuiltin

func IsBuiltin(name string) bool

IsBuiltin reports whether name resolves to the built-in root. Dir looks there first, so a theme is built-in exactly when Dir lands there — even if an installed copy of the same name exists underneath.

func List

func List() []string

List returns every theme name from both roots, sorted. "default" is always listed: it is the baseline every other theme is layered on, and Load requires it (a missing or broken default is a startup error).

func Load

func Load(name string, funcMap template.FuncMap) (*template.Template, string, error)

Load builds the template set for name. Anything wrong with the named theme (unknown, unparsable) is logged and default is loaded instead; only a broken shared/default set is an error, because nothing can render without it.

func Screenshot

func Screenshot(name string) (string, bool)

Screenshot returns the path of a theme's preview image — screenshot.png or screenshot.jpg beside its templates/, the same file the directory requires of a published theme — and whether it has one.

func StaticHandler

func StaticHandler(active func() string) gin.HandlerFunc

StaticHandler serves /theme/* from the active theme's static/ directory, falling back to default's so an override-only theme still gets the base CSS. The path is cleaned as an absolute path first so ".." cannot climb out of static/.

func ValidName

func ValidName(name string) bool

ValidName reports whether name may be looked up on disk.

func ValidateFiles

func ValidateFiles(files map[string][]byte) error

ValidateFiles checks a theme's files as the installer and the directory see them (paths relative to the theme root, e.g. "templates/home.html"): there must be at least one template, each templates/*.html must parse on top of the shared and default sets, and every {{ template }} they reference must exist somewhere in that set. Files in subdirectories of templates/ are not loaded by Load and are ignored here too.

Types

This section is empty.

Directories

Path Synopsis
Package installer installs, updates and removes themes from the theme directory at runtime, for the admin UI.
Package installer installs, updates and removes themes from the theme directory at runtime, for the admin UI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL