Documentation
¶
Overview ¶
Package funcs provides content-specific template functions for filtering and grouping.
Package funcs provides core template functions for arithmetic, logic, and comparisons.
Package funcs provides date and time formatting template functions.
Package funcs provides dictionary and data structure manipulation template functions.
Package funcs provides site-specific template functions requiring generator context.
Package funcs provides string manipulation template functions.
Index ¶
- func Add(a, b any) (any, error)
- func And(values ...any) bool
- func Append(slice []any, elem any) []any
- func Concat(slices ...[]*content.Node) []*content.Node
- func Cond(condition bool, trueVal, falseVal any) any
- func Contains(haystack, needle any) (bool, error)
- func Default(def, val any) any
- func Dict(values ...any) (map[string]any, error)
- func EndsWith(s, suffix string) bool
- func Eq(a, b any) bool
- func First(items any) (any, error)
- func FormatDate(t time.Time, layout ...string) string
- func Ge(a, b any) (bool, error)
- func Gt(a, b any) (bool, error)
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func In(needle, haystack any) (bool, error)
- func Intersect(a, b []any) []any
- func Join(items []string, sep string) string
- func Last(items any) (any, error)
- func Le(a, b any) (bool, error)
- func Len(v any) (int, error)
- func Limit(max any, items any) (any, error)
- func LoadAttribute(path string) (template.HTML, error)
- func LoadData(path string) (template.HTML, error)
- func Lower(s string) string
- func Lt(a, b any) (bool, error)
- func MakeSlice(items ...any) []any
- func Merge(dicts ...map[string]any) map[string]any
- func Ne(a, b any) bool
- func Now() time.Time
- func Or(values ...any) bool
- func ParseDate(layout, value string) (time.Time, error)
- func Pluralize(singular string, count any) (string, error)
- func Priority(vals ...any) string
- func RelatedPosts(pageData any, allPosts []*content.Node) []*content.Node
- func Replace(s, old, replacement string) string
- func Reverse(items any) any
- func SafeHTML(s string) template.HTML
- func Slice(v any, start int, end ...int) (any, error)
- func SortBy(field string, nodes []*content.Node) ([]*content.Node, error)
- func Split(s, sep string) []string
- func StartsWith(s, prefix string) bool
- func Sub(a, b int) int
- func Trim(s string) string
- func Union(a, b []any) []any
- func Uniq(items []any) []any
- func Upper(s string) string
- func Urlize(s string) string
- func Where(items any, field string, value any) (any, error)
- type Group
- type MacroRenderer
- type SiteContext
- type SiteFuncs
- func (sf *SiteFuncs) AssetPath(relPath string, context any) (string, error)
- func (sf *SiteFuncs) CurrentLang(context any) string
- func (sf *SiteFuncs) GetSection(path string) (*content.Node, error)
- func (sf *SiteFuncs) LangURL(langCode string, pageOrPath any) string
- func (sf *SiteFuncs) RenderMarkdown(input string) (template.HTML, error)
- func (sf *SiteFuncs) Translate(key string, langOrContext ...any) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cond ¶ added in v0.0.36
Cond is a ternary conditional operator: returns trueVal if condition is true, otherwise falseVal
func Default ¶
Default returns the value if it's non-empty, otherwise returns the default. Now supports any type for both val and def (improved from string-only).
func FormatDate ¶
FormatDate formats a time.Time with an optional layout.
func In ¶ added in v0.0.36
In is an alias for Contains with reversed argument order for more readable syntax. Usage: {{ if in "golang" .Tags }}...{{ end }} This is equivalent to: {{ if contains .Tags "golang" }}...{{ end }}
func LoadAttribute ¶
LoadAttribute loads file content as HTML-escaped attribute value.
func Merge ¶ added in v0.0.36
Merge merges multiple dictionaries into one. Later dictionaries override earlier ones.
func RelatedPosts ¶ added in v0.0.26
RelatedPosts finds posts related to the given page based on tag overlap.
func Reverse ¶
Reverse returns a copy of the slice with elements in reverse order. Supports both []*content.Node and generic []any.
func Slice ¶ added in v0.0.36
Slice returns a sub-slice of a slice, array, or string. Usage: {{ slice .Items 0 5 }}
func SortBy ¶ added in v0.0.9
SortBy sorts a slice of nodes by a given field (only "date" currently supported).
func StartsWith ¶ added in v0.0.12
StartsWith is an alias for HasPrefix.
Types ¶
type MacroRenderer ¶
type MacroRenderer struct {
// contains filtered or unexported fields
}
MacroRenderer holds methods for rendering template macros.
func NewMacroRenderer ¶
func NewMacroRenderer(templates *template.Template) *MacroRenderer
NewMacroRenderer creates a new macro renderer.
func (*MacroRenderer) RenderPagination ¶
func (mr *MacroRenderer) RenderPagination(siteConfig map[string]any) func(data map[string]any) (template.HTML, error)
RenderPagination renders the pagination macro.
type SiteContext ¶
type SiteContext struct {
BaseURL string
ContentMap map[string]*content.Node
Markdown goldmark.Markdown
I18n *i18n.I18n
}
SiteContext provides access to site-wide data needed by template functions.
type SiteFuncs ¶
type SiteFuncs struct {
// contains filtered or unexported fields
}
SiteFuncs holds template functions that require site context.
func NewSiteFuncs ¶
func NewSiteFuncs(ctx *SiteContext) *SiteFuncs
NewSiteFuncs creates a new SiteFuncs with the given context.
func (*SiteFuncs) CurrentLang ¶ added in v0.0.33
CurrentLang returns the current language code from context. Usage in templates: {{ currentLang .Page }}
func (*SiteFuncs) GetSection ¶
GetSection retrieves a section node by path.
func (*SiteFuncs) LangURL ¶ added in v0.0.33
LangURL generates a URL for a specific language version of a page. Usage in templates:
{{ langURL "fr" .Page }} - Get current page in French
{{ langURL "en" .Page.Permalink }} - Get specific path in English
func (*SiteFuncs) RenderMarkdown ¶
RenderMarkdown renders markdown content to HTML.