Documentation
¶
Overview ¶
Package template provides the Go html/template engine with custom functions and template lookup resolution.
Index ¶
- func BuildRouteData(page *engine.Page, site *engine.SiteContext, theme *engine.ThemeConfig) *engine.RouteData
- func BuildShortcodeFuncMap(cfg ShortcodeFuncMapConfig) htmltemplate.FuncMap
- func PaginationURL(base string, n int) string
- type Engine
- func (e *Engine) CSSURL() string
- func (e *Engine) CachedCSS() string
- func (e *Engine) CurrentLangPtr() *string
- func (e *Engine) ForceReload()
- func (e *Engine) Load(resolver *engine.ThemeResolver, devMode bool) error
- func (e *Engine) Render(templateName string, data *engine.RouteData) ([]byte, error)
- func (e *Engine) SetAsideCSS(css string)
- func (e *Engine) SetAssetPipeline(resolver *asset.Resolver, manifest *asset.Manifest)
- func (e *Engine) SetCodeBlockCSS(css string)
- func (e *Engine) SetCurrentLang(lang string)
- func (e *Engine) SetDirectiveCSS(css string)
- func (e *Engine) SetI18nStrings(st *i18n.StringTable)
- func (e *Engine) SetImageProcessor(p *asset.ImageProcessor)
- func (e *Engine) SetPageIndex(idx *content.PageIndex)
- func (e *Engine) SetPluginFuncs(funcs map[string]any)
- func (e *Engine) SetSiteContext(site *engine.SiteContext)
- func (e *Engine) SetTokenCSSURL(url string)
- func (e *Engine) SetURLResolver(r *engine.URLResolver)
- type ShortcodeFuncMapConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildRouteData ¶
func BuildRouteData(page *engine.Page, site *engine.SiteContext, theme *engine.ThemeConfig) *engine.RouteData
BuildRouteData constructs the unified RouteData context for a page render.
func BuildShortcodeFuncMap ¶
func BuildShortcodeFuncMap(cfg ShortcodeFuncMapConfig) htmltemplate.FuncMap
BuildShortcodeFuncMap constructs a FuncMap suitable for shortcode templates. It creates a temporary Engine wired to the caller's pointers so closures see mutations made through those pointers during the build.
func PaginationURL ¶
PaginationURL returns the URL for the Nth pagination page of a collection. Page 1 maps to the collection's base URL; N>1 maps to "<base>page/N/".
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine loads templates from the resolved lookup chain and renders pages to HTML.
func (*Engine) CurrentLangPtr ¶
CurrentLangPtr returns a pointer to the current language field, suitable for capture by plugin closures that resolve i18n strings at render time.
func (*Engine) ForceReload ¶
func (e *Engine) ForceReload()
ForceReload resets the loaded flag so the next Load() call re-parses all templates, components, and partials from disk.
func (*Engine) Load ¶
func (e *Engine) Load(resolver *engine.ThemeResolver, devMode bool) error
Load initializes the template system: loads base templates for each layout, sets up the component registry, and builds the FuncMap. In production mode (!devMode), the embedded CSS bundle is minified via esbuild. The output is always fingerprinted.
func (*Engine) SetAsideCSS ¶ added in v1.2.0
SetAsideCSS sets the opt-in aside style overlay CSS (the embedded callouts-galaxy.css when markdown.asides.style is "galaxy"). Appended to the main CSS bundle like code block CSS. Must be called before Load().
func (*Engine) SetAssetPipeline ¶
SetAssetPipeline sets the asset resolver and manifest used by asset template functions. Must be called before Load().
func (*Engine) SetCodeBlockCSS ¶
SetCodeBlockCSS sets dynamically generated code block syntax theme CSS. Must be called before Load().
func (*Engine) SetCurrentLang ¶
SetCurrentLang sets a fallback language for the base-funcMap t() closure. This is NOT required for correct rendering: Render resolves the language per-page from RouteData and installs a language-specific t() via funcMapForLang on the cached template. Provided for API completeness.
func (*Engine) SetDirectiveCSS ¶ added in v1.2.0
SetDirectiveCSS sets the concatenated CSS sidecars of all generic directives (internal/directive Registry.CSS). Appended unlayered to the main CSS bundle, same treatment as code block CSS. Must be called before Load().
func (*Engine) SetI18nStrings ¶
func (e *Engine) SetI18nStrings(st *i18n.StringTable)
SetI18nStrings sets the translation string table for the t() template function. Must be called before Load().
func (*Engine) SetImageProcessor ¶
func (e *Engine) SetImageProcessor(p *asset.ImageProcessor)
SetImageProcessor sets the image processor used by the resize_image template function. Must be called before Load().
func (*Engine) SetPageIndex ¶
SetPageIndex sets the page index for O(1) ref/relref lookups. Must be called before Load().
func (*Engine) SetPluginFuncs ¶
SetPluginFuncs sets additional template functions provided by plugins. Must be called before Load().
func (*Engine) SetSiteContext ¶
func (e *Engine) SetSiteContext(site *engine.SiteContext)
SetSiteContext sets the site context used by template functions. Must be called before the first Render() call.
func (*Engine) SetTokenCSSURL ¶
SetTokenCSSURL sets the external URL for the theme token CSS file.
func (*Engine) SetURLResolver ¶
func (e *Engine) SetURLResolver(r *engine.URLResolver)
SetURLResolver sets the URL resolver for relURL/absURL template functions. Must be called before Load().
type ShortcodeFuncMapConfig ¶
type ShortcodeFuncMapConfig struct {
Site **engine.SiteContext
Resolver *engine.ThemeResolver
AssetResolver *asset.Resolver
AssetManifest *asset.Manifest
ImageProcessor *asset.ImageProcessor
PageIndex **content.PageIndex
}
ShortcodeFuncMapConfig holds the dependencies needed to build a FuncMap for shortcode templates. Component registry, plugin funcs, and i18n are intentionally excluded to avoid concurrency issues during parallel markdown rendering.