render

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package render loads layout templates and executes them for pages.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingLayout = errors.New("layout not found")

ErrMissingLayout is returned by Execute for an unknown layout name.

Functions

func AbsURL

func AbsURL(baseURL, p string) string

AbsURL is RelURL with baseURL's scheme and host. If baseURL has no host it behaves like RelURL.

func Funcs

func Funcs(o FuncOptions) template.FuncMap

Funcs returns the template functions (spec §9.3). "partial" is bound to each layout's template set by Load.

func RelURL

func RelURL(baseURL, p string) string

RelURL prefixes a site path with the path part of baseURL, so sites deployed under a subpath (GitHub Pages project sites) link correctly. Absolute URLs are returned unchanged.

func Static

func Static() fs.FS

Static returns the built-in theme's static files, such as css/tryck.css. A file with the same path in the theme's or site's static directory replaces it.

Types

type Dir

type Dir struct {
	Path  string
	Label string
}

Dir is a layouts directory and how it is named in diagnostics (relative to the project root).

type FuncOptions

type FuncOptions struct {
	BaseURL     string
	DateFormat  string                       // default layout for dateFormat
	Markdownify func(string) (string, error) // inline Markdown to HTML
}

FuncOptions configures the template functions of a site.

type NavLink struct {
	Title string
	URL   string
}

NavLink is a header link.

type PageInfo

type PageInfo = plugin.PageInfo

PageInfo is the per-page data available to templates.

type SiteInfo

type SiteInfo = plugin.SiteInfo

SiteInfo is the site-wide data available to templates.

type TemplateData

type TemplateData struct {
	Site        SiteInfo
	Page        *PageInfo
	Content     template.HTML     // rendered body, already trusted
	Nav         *plugin.NavNode   // full tree with Active/InPath set for this page
	TOC         []plugin.TOCEntry // from the toc plugin, nil if disabled
	Prev, Next  *PageInfo         // nil at the ends
	Stylesheets []string          // site paths of plugin CSS to link in <head>
	Theme       ThemeData         // theme settings from the config
	Dev         bool              // true in tryck dev
}

TemplateData is the dot value of every layout (spec §9.2).

type Templates

type Templates struct {
	// contains filtered or unexported fields
}

Templates holds one executable template set per layout.

func Load

func Load(dirs []Dir, funcs template.FuncMap) (*Templates, []diag.Diagnostic)

Load parses the embedded default layouts, overridden file by file by those in dirs (lowest priority first: the theme's, then the site's). Directories that do not exist are skipped.

func (*Templates) Execute

func (t *Templates) Execute(w io.Writer, layout string, data *TemplateData) error

Execute renders data with the named layout (file name without .html).

func (*Templates) Has

func (t *Templates) Has(layout string) bool

Has reports whether a layout exists.

type ThemeData

type ThemeData struct {
	Accent      template.CSS  // validated CSS color, or ""
	AccentDark  template.CSS  // accent in dark mode
	ColorScheme string        // auto, light or dark
	Nav         []NavLink     // header links
	Footer      template.HTML // rendered inline Markdown
	CSS         []string      // extra stylesheets
	Params      map[string]any
}

ThemeData is the theme section of the config, ready for templates.

Jump to

Keyboard shortcuts

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