template

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(input interface{}, args ...interface{}) interface{}

func AbsoluteURL

func AbsoluteURL(input interface{}, args ...interface{}) interface{}

func Append

func Append(input interface{}, args ...interface{}) interface{}

func ApplyFilter

func ApplyFilter(name string, input interface{}, args ...interface{}) interface{}

ApplyFilter dispatches a filter by name with the given input and optional arguments.

func CacheBust

func CacheBust(input interface{}, args ...interface{}) interface{}

func Capitalize

func Capitalize(input interface{}, args ...interface{}) interface{}

func Ceil

func Ceil(input interface{}, args ...interface{}) interface{}

func Compact

func Compact(input interface{}, args ...interface{}) interface{}

func Complement

func Complement(input interface{}, args ...interface{}) interface{}

func Concat

func Concat(input interface{}, args ...interface{}) interface{}

func Contains

func Contains(input interface{}, args ...interface{}) interface{}

func DateFormat

func DateFormat(input interface{}, args ...interface{}) interface{}

func Default

func Default(input interface{}, args ...interface{}) interface{}

func DetectCircularLayouts

func DetectCircularLayouts(layoutsDir string) error

DetectCircularLayouts checks for circular references in layout chains.

func DiscoverRenderHooks

func DiscoverRenderHooks(layoutsDir, engine string) (map[string]string, error)

func DividedBy

func DividedBy(input interface{}, args ...interface{}) interface{}

func Downcase

func Downcase(input interface{}, args ...interface{}) interface{}

func Escape

func Escape(input interface{}, args ...interface{}) interface{}

func ExtractLayoutParent

func ExtractLayoutParent(path string) string

ExtractLayoutParent reads a layout file and looks for a parent layout reference in its front matter. Returns the parent layout name, or "" if none found.

func FindRE

func FindRE(input interface{}, args ...interface{}) interface{}

func First

func First(input interface{}, args ...interface{}) interface{}

func Flatten

func Flatten(input interface{}, args ...interface{}) interface{}

func Floor

func Floor(input interface{}, args ...interface{}) interface{}

func GetHash

func GetHash(input interface{}, args ...interface{}) interface{}

func GroupBy

func GroupBy(input interface{}, args ...interface{}) interface{}

func InitMarkdownify

func InitMarkdownify(opts content.MarkdownOptions)

InitMarkdownify creates the shared goldmark instance for the markdownify filter using config-driven options. Called from createEngine after config is loaded. TemplateTags is always false: markdownify processes values that have already been through template rendering, so tag protection is not needed.

func Intersect

func Intersect(input interface{}, args ...interface{}) interface{}

func IsBuiltinFilter

func IsBuiltinFilter(name string) bool

IsBuiltinFilter reports whether name is a known built-in filter.

func JSONFilter

func JSONFilter(input interface{}, args ...interface{}) interface{}

func Join

func Join(input interface{}, args ...interface{}) interface{}

func Last

func Last(input interface{}, args ...interface{}) interface{}

func Limit added in v0.4.0

func Limit(input interface{}, args ...interface{}) interface{}

func Map

func Map(input interface{}, args ...interface{}) interface{}

func Markdownify

func Markdownify(input interface{}, args ...interface{}) interface{}

func Minus

func Minus(input interface{}, args ...interface{}) interface{}

func Modulo

func Modulo(input interface{}, args ...interface{}) interface{}

func NewlineToBr

func NewlineToBr(input interface{}, args ...interface{}) interface{}

func Plus

func Plus(input interface{}, args ...interface{}) interface{}

func Prepend

func Prepend(input interface{}, args ...interface{}) interface{}

func ProcessBlockShortcodes added in v0.5.0

func ProcessBlockShortcodes(input []byte, callback BlockShortcodeCallback) ([]byte, error)

ProcessBlockShortcodes scans post-Goldmark HTML for Go template block shortcode pairs ({{% tag "args" %}}...{{% /tag %}}) and replaces each with the callback's output. Nesting is resolved innermost-first. Tags inside <pre> and <code> elements are treated as literal text and left untouched.

func RegisterAssetFilters

func RegisterAssetFilters(projectRoot string, subdirs ...string)

func RegisterBlockShortcode

func RegisterBlockShortcode(name string, fn BlockShortcodeFunc) error

RegisterBlockShortcode registers a block shortcode (with inner content).

func RegisterBuiltinFilters

func RegisterBuiltinFilters(engine TemplateEngine) error

RegisterBuiltinFilters registers all built-in filters on the given engine.

func RegisterInlineTag

func RegisterInlineTag(engine TemplateEngine)

RegisterInlineTag registers the {% inline %} tag on the given engine. The tag reads a file relative to the content file's directory and inserts its raw contents without template processing.

func RegisterShortcode

func RegisterShortcode(name string, fn ShortcodeFunc) error

RegisterShortcode registers a shortcode that works in both Liquid and Go template engines.

func RegisterURLFilters added in v0.4.0

func RegisterURLFilters(baseURL string)

func RenderTemplate

func RenderTemplate(source string, sourcePath string, ctx map[string]interface{}) (string, error)

RenderTemplate renders a template string with the given context. Returns an error that includes the source file path on failure.

func Replace

func Replace(input interface{}, args ...interface{}) interface{}

func ReplaceFirst

func ReplaceFirst(input interface{}, args ...interface{}) interface{}

func ReplaceRE

func ReplaceRE(input interface{}, args ...interface{}) interface{}

func ResetShortcodes

func ResetShortcodes()

ResetShortcodes clears all registered shortcodes (useful for testing).

func ResolveLayout

func ResolveLayout(page *content.Page, layoutsDir string, engine string, permalinkCfg map[string]string) (string, error)

ResolveLayout finds the correct layout file for a page following the lookup order: 1. Front matter layout (bare names get engine fallback; extension-bearing used as-is) 2. "post" (for pages in date-based permalink sections) 3. Section name (for index pages) 4. "default" Filename matching was removed in issue #902 — layouts are either explicitly set or use convention/default fallbacks. For the Liquid engine, auto candidates try .liquid then bare .html per candidate before moving to the next candidate (per-candidate interleaving). Returns error if no layout file is found on disk.

func ResolveLayoutChain

func ResolveLayoutChain(layoutPath string, layoutsDir string, engine string) ([]string, error)

ResolveLayoutChain follows layout: directives in layout front matter to build the full chain from innermost to root. Returns the ordered list of layout file paths. Parent names follow the same bare-name vs extension-bearing rules as front matter layout. Returns error if the chain exceeds maxDepth (10) or if a referenced layout is not found.

func ResolveLayoutForFormat

func ResolveLayoutForFormat(page *content.Page, layoutsDir string, engine string, format string, permalinkCfg map[string]string) (string, error)

ResolveLayoutForFormat finds the correct layout for a specific output format. Mirrors ResolveLayout with the output format infixed before the engine extension. One algorithm, one lookup order — no "single" concept. For the Liquid engine, each candidate tries .format.liquid then bare .format.

func ResolveLayoutForFormatWithCascade added in v0.4.0

func ResolveLayoutForFormatWithCascade(page *content.Page, layoutsDir, engine, format string, permalinkCfg map[string]string, cascadeData map[string]interface{}) (string, error)

ResolveLayoutForFormatWithCascade resolves format layout considering cascade data. Mirrors ResolveLayoutWithCascade with the output format infixed. Delegates to ResolveLayoutForFormat for auto candidates.

func ResolveLayoutWithCascade

func ResolveLayoutWithCascade(page *content.Page, layoutsDir, engine string, permalinkCfg map[string]string, cascadeData map[string]interface{}) (string, error)

ResolveLayoutWithCascade resolves layout considering cascade data. Named layouts (front matter or cascade) use resolveNamedLayout: bare names get engine fallback (.liquid → .html), extension-bearing names are used as-is. When no explicit layout is set, falls through to ResolveLayout for auto candidates.

func ResolveTaxonomyLayout

func ResolveTaxonomyLayout(taxonomyName string, layoutOverride string, layoutsDir string, engine string) (string, error)

ResolveTaxonomyLayout finds the layout for a taxonomy page. Lookup per candidate: taxonomies/<name> then root <name>, with per-candidate .liquid → .html interleaving for the Liquid engine.

func Reverse

func Reverse(input interface{}, args ...interface{}) interface{}

func Round

func Round(input interface{}, args ...interface{}) interface{}

func SafeHTML

func SafeHTML(input interface{}, args ...interface{}) interface{}

func Size

func Size(input interface{}, args ...interface{}) interface{}

func Slugify

func Slugify(input interface{}, args ...interface{}) interface{}

func Sort

func Sort(input interface{}, args ...interface{}) interface{}

func Split

func Split(input interface{}, args ...interface{}) interface{}

func Strip

func Strip(input interface{}, args ...interface{}) interface{}

func StripHTML

func StripHTML(input interface{}, args ...interface{}) interface{}

func StripLayoutFrontMatter

func StripLayoutFrontMatter(s string) string

StripLayoutFrontMatter removes YAML front matter (--- delimited) from layout content. Returns the content after the closing --- delimiter.

func Times

func Times(input interface{}, args ...interface{}) interface{}

func Truncate

func Truncate(input interface{}, args ...interface{}) interface{}

func TruncateWords

func TruncateWords(input interface{}, args ...interface{}) interface{}

func URLDecode

func URLDecode(input interface{}, args ...interface{}) interface{}

func URLEncode

func URLEncode(input interface{}, args ...interface{}) interface{}

func URLFilter

func URLFilter(input interface{}, args ...interface{}) interface{}

func Union

func Union(input interface{}, args ...interface{}) interface{}

func Uniq

func Uniq(input interface{}, args ...interface{}) interface{}

func Upcase

func Upcase(input interface{}, args ...interface{}) interface{}

func Where

func Where(input interface{}, args ...interface{}) interface{}

Types

type BlockShortcodeCallback added in v0.5.0

type BlockShortcodeCallback func(name string, args []string, content string) (string, error)

BlockShortcodeCallback receives the shortcode name, quoted arguments, and inner HTML content. It returns the rendered replacement HTML.

type BlockShortcodeFunc

type BlockShortcodeFunc func(args []string, content string) string

BlockShortcodeFunc handles block shortcodes (with inner content).

type FilterFunc

type FilterFunc func(input interface{}, args ...interface{}) interface{}

FilterFunc is the signature for template filter functions.

type PageContext

type PageContext struct {
	Title        string
	URL          string
	Date         interface{}
	Collection   string
	FrontMatter  map[string]interface{}
	Translations []map[string]interface{} // translation info: url, lang
	TOC          []content.TOCEntry
}

PageContext holds per-page data available as {{ page.* }}.

type PluginCallError added in v0.7.0

type PluginCallError struct {
	Kind    string // "filter" or "shortcode"
	Name    string
	Wrapped error
	// contains filtered or unexported fields
}

func NewPluginCallError added in v0.7.0

func NewPluginCallError(kind, name string, err error) *PluginCallError

func (*PluginCallError) Error added in v0.7.0

func (e *PluginCallError) Error() string

func (*PluginCallError) GetError added in v0.7.0

func (e *PluginCallError) GetError() *liquid.Error

type ShortcodeFunc

type ShortcodeFunc func(args []string) string

ShortcodeFunc handles inline shortcodes (no inner content).

func GetShortcode

func GetShortcode(name string) (ShortcodeFunc, error)

GetShortcode returns a registered inline shortcode by name.

type SiteContext

type SiteContext struct {
	Title        string
	BaseURL      string
	Language     string
	LanguageData map[string]interface{} // structured language data (code, title, root, strings)
	Data         map[string]interface{}
	Pages        []*content.Page
}

SiteContext holds site-wide data available as {{ site.* }}.

type TagFunc

type TagFunc func(args []string, content string) string

TagFunc is the signature for custom template tag/shortcode functions.

type Template

type Template interface {
	Render(ctx map[string]interface{}) ([]byte, error)
}

Template is a parsed template that can be rendered with a context.

type TemplateContext

type TemplateContext struct {
	Site        SiteContext
	Page        PageContext
	Collections map[string]interface{}
	Taxonomies  map[string]interface{}
	Content     string // rendered HTML body
	Pagination  *pagination.PaginationContext
	Custom      map[string]interface{} // dynamic top-level variables (e.g., pagination "as" alias)
}

TemplateContext is the complete context object passed to templates during rendering.

func BuildTemplateContext

func BuildTemplateContext(page *content.Page, siteData map[string]interface{}, allPages []*content.Page, collections map[string]interface{}, taxonomies map[string]interface{}, pagCtx *pagination.PaginationContext, asName string) *TemplateContext

BuildTemplateContext assembles the complete template context for rendering a page. For paginated pages, pass the PaginationContext and the "as" variable name. For non-paginated pages, pass nil and "".

func (*TemplateContext) ToMap

func (tc *TemplateContext) ToMap() map[string]interface{}

ToMap converts the TemplateContext to a raw map[string]interface{} for use with template engines (e.g., osteele/liquid) that require a plain map. The map shape matches the spec §3 context: page.*, site.*, collections.*, taxonomies.*, with pagination and custom "as" variables hoisted to the top level.

type TemplateEngine

type TemplateEngine interface {
	Parse(name string, content []byte) (Template, error)
	AddFilter(name string, fn FilterFunc) error
	AddTag(name string, fn TagFunc) error
}

TemplateEngine is the abstraction over Liquid and Go template engines.

func NewGoEngine

func NewGoEngine() TemplateEngine

NewGoEngine creates a new Go html/template engine.

func NewLiquidEngine

func NewLiquidEngine() TemplateEngine

NewLiquidEngine creates a new Liquid template engine with standard tags and filters.

Jump to

Keyboard shortcuts

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