template

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package template provides the Go html/template engine with custom functions and template lookup resolution.

Index

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

func PaginationURL(base string, n int) string

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 NewEngine

func NewEngine() *Engine

NewEngine creates a new template Engine.

func (*Engine) CSSURL

func (e *Engine) CSSURL() string

CSSURL returns the root-relative URL of the embedded CSS bundle.

func (*Engine) CachedCSS

func (e *Engine) CachedCSS() string

CachedCSS returns the concatenated embedded CSS bundle.

func (*Engine) CurrentLangPtr

func (e *Engine) CurrentLangPtr() *string

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) Render

func (e *Engine) Render(templateName string, data *engine.RouteData) ([]byte, error)

Render renders a page using its resolved template and RouteData context.

func (*Engine) SetAssetPipeline

func (e *Engine) SetAssetPipeline(resolver *asset.Resolver, manifest *asset.Manifest)

SetAssetPipeline sets the asset resolver and manifest used by asset template functions. Must be called before Load().

func (*Engine) SetCodeBlockCSS

func (e *Engine) SetCodeBlockCSS(css string)

SetCodeBlockCSS sets dynamically generated code block syntax theme CSS. Must be called before Load().

func (*Engine) SetCurrentLang

func (e *Engine) SetCurrentLang(lang string)

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) 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

func (e *Engine) SetPageIndex(idx *content.PageIndex)

SetPageIndex sets the page index for O(1) ref/relref lookups. Must be called before Load().

func (*Engine) SetPluginFuncs

func (e *Engine) SetPluginFuncs(funcs map[string]any)

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

func (e *Engine) SetTokenCSSURL(url string)

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.

Jump to

Keyboard shortcuts

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