plugins

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 42 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 plugins holds tryck's built-in plugins and the registry that enables, configures and orders them for a build.

Index

Constants

View Source
const DefaultMermaidURL = "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs"

DefaultMermaidURL loads mermaid 11 from jsDelivr. Point url at a copy in static/ for sites that must work offline.

Variables

View Source
var (
	KindMathInline = ast.NewNodeKind("MathInline")
	KindMathBlock  = ast.NewNodeKind("MathBlock")
)
View Source
var KindMermaidBlock = ast.NewNodeKind("MermaidBlock")

KindMermaidBlock is the node kind of MermaidBlock.

Functions

func Each

func Each[T any](s *Set) []T

Each returns the enabled plugins implementing T, in phase order.

Types

type Feed added in v0.4.0

type Feed struct {
	Sections []string `yaml:"sections"`
	Limit    int      `yaml:"limit"`
	Format   string   `yaml:"format"`
	Author   string   `yaml:"author"`
	// contains filtered or unexported fields
}

Feed writes an Atom (or RSS) feed of the pages that have a date, newest first: one for each section in Sections, at <section>feed.xml. Drafts and older versions are left out, and a section without dated pages gets no feed. Pages link the feeds of their sections in <head>.

func (*Feed) ConfigKeys added in v0.4.0

func (*Feed) ConfigKeys() []string

func (*Feed) Init added in v0.4.0

func (f *Feed) Init(cfg map[string]any, site plugin.SiteInfo) error

func (*Feed) Name added in v0.4.0

func (*Feed) Name() string

func (*Feed) OnBuildComplete added in v0.4.0

func (f *Feed) OnBuildComplete(v plugin.SiteView, out plugin.Outputs) error

func (*Feed) OnPageParsed added in v0.4.0

func (f *Feed) OnPageParsed(p *plugin.Page) error

OnPageParsed keeps the page's first paragraph as its summary.

func (*Feed) OnPageRendered added in v0.4.0

func (f *Feed) OnPageRendered(p *plugin.Page, v plugin.SiteView) error

OnPageRendered links the feeds of the page's sections in <head>.

type Formula added in v0.11.0

type Formula struct {
	Display bool
	TeX     string
	Offset  int // of the formula in the source, for diagnostics; -1 if unknown
	HTML    string
}

Formula is a TeX formula in a page. HTML is set once it is rendered.

type Highlight

type Highlight struct {
	Theme       string `yaml:"theme"`
	DarkTheme   string `yaml:"darkTheme"` // "" = Theme in both modes
	LineNumbers bool   `yaml:"lineNumbers"`
}

Highlight colors fenced code blocks with chroma. It emits CSS classes rather than inline styles and writes the theme to /css/chroma.css, so themes and dark mode can be switched in CSS: Theme applies in light mode and DarkTheme in dark mode (see the built-in theme's colorScheme).

func (*Highlight) ConfigKeys added in v0.2.0

func (*Highlight) ConfigKeys() []string

func (*Highlight) Extend

func (h *Highlight) Extend(m goldmark.Markdown)

func (*Highlight) Init

func (h *Highlight) Init(cfg map[string]any, _ plugin.SiteInfo) error

func (*Highlight) Name

func (*Highlight) Name() string

func (*Highlight) OnBuildComplete

func (h *Highlight) OnBuildComplete(_ plugin.SiteView, out plugin.Outputs) error

func (*Highlight) Stylesheets

func (*Highlight) Stylesheets() []string

type LLMsTxt added in v0.8.0

type LLMsTxt struct {
	Pages    bool     `yaml:"pages"`
	Full     bool     `yaml:"full"`
	Details  string   `yaml:"details"`
	Optional []string `yaml:"optional"`
	Exclude  []string `yaml:"exclude"`
	// Versions gives each older version its own llms.txt, copies and
	// llms-full.txt under its URL prefix ("/v1/llms.txt").
	Versions bool `yaml:"versions"`
	// UnsafeHTML keeps raw HTML, as build.unsafeHTML does for pages;
	// otherwise it is removed, like HTML comments and scripts are from
	// pages.
	UnsafeHTML bool `yaml:"-"`
	// contains filtered or unexported fields
}

LLMsTxt writes /llms.txt (https://llmstxt.org, v2): the site's title and description, then a list of its pages with their descriptions, one section per top-level folder of the navigation. With Pages, every page is also written as Markdown at its URL ("/guide/setup/" -> "/guide/setup/index.md"), llms.txt links those, and each page links its copy and llms.txt in <head>. With Full, llms-full.txt holds every page in one file.

The Markdown is the page source as written, with front matter removed, the page title as its first line and every link and image made absolute. With Versions, each older version gets the same files under its prefix ("/v1/llms.txt"). Drafts and pages under Exclude are left out; pages under Optional are listed in an "Optional" section, the convention for secondary links. Raw HTML is removed unless UnsafeHTML is set.

func (*LLMsTxt) ConfigKeys added in v0.8.0

func (*LLMsTxt) ConfigKeys() []string

func (*LLMsTxt) Init added in v0.8.0

func (l *LLMsTxt) Init(cfg map[string]any, site plugin.SiteInfo) error

func (*LLMsTxt) Name added in v0.8.0

func (*LLMsTxt) Name() string

func (*LLMsTxt) OnBuildComplete added in v0.8.0

func (l *LLMsTxt) OnBuildComplete(v plugin.SiteView, out plugin.Outputs) error

func (*LLMsTxt) OnPageParsed added in v0.8.0

func (l *LLMsTxt) OnPageParsed(p *plugin.Page) error

OnPageParsed records where the page's links are and what they point to. Links have their final URLs by now.

func (*LLMsTxt) OnPageRendered added in v0.9.0

func (l *LLMsTxt) OnPageRendered(p *plugin.Page, _ plugin.SiteView) error

OnPageRendered links the page's Markdown copy and llms.txt in <head>, so agents find them from the page (llms.txt v2).

type LinkCheck

type LinkCheck struct {
	FailOnBroken bool `yaml:"failOnBroken"`
	// contains filtered or unexported fields
}

LinkCheck reports internal links to pages or files that do not exist (link.broken) and #fragments missing on their target page (link.anchor). Links are recorded per page while parsing, after tryck has rewritten them to site URLs, and checked once every page is known.

func (*LinkCheck) ConfigKeys added in v0.2.0

func (*LinkCheck) ConfigKeys() []string

func (*LinkCheck) Init

func (l *LinkCheck) Init(cfg map[string]any, site plugin.SiteInfo) error

func (*LinkCheck) Name

func (*LinkCheck) Name() string

func (*LinkCheck) OnBuildComplete

func (l *LinkCheck) OnBuildComplete(s plugin.SiteView, _ plugin.Outputs) error

func (*LinkCheck) OnPageParsed

func (l *LinkCheck) OnPageParsed(p *plugin.Page) error

func (*LinkCheck) Priority

func (*LinkCheck) Priority() int

Priority runs the check after other finalizers have added their files.

type Math added in v0.11.0

type Math struct {
	Inline bool              `yaml:"inline"`
	Macros map[string]string `yaml:"macros"`
	// contains filtered or unexported fields
}

Math renders TeX formulas to MathML at build time with KaTeX, so pages need no script or stylesheet for them; browsers draw them with a math font on the reader's system. It understands the syntax GitHub does: $...$ inline (with Inline), $$...$$ for a displayed formula, alone on its lines or within a paragraph, and ```math blocks. A formula KaTeX cannot parse is a math.error warning and is shown as code.

func (*Math) ConfigKeys added in v0.11.0

func (*Math) ConfigKeys() []string

func (*Math) Extend added in v0.11.0

func (m *Math) Extend(md goldmark.Markdown)

func (*Math) Init added in v0.11.0

func (m *Math) Init(cfg map[string]any, _ plugin.SiteInfo) error

func (*Math) Name added in v0.11.0

func (*Math) Name() string

func (*Math) OnPageParsed added in v0.11.0

func (m *Math) OnPageParsed(p *plugin.Page) error

OnPageParsed renders the page's formulas and reports the ones KaTeX cannot parse.

type MathBlock added in v0.11.0

type MathBlock struct {
	ast.BaseBlock
	Formula
	// contains filtered or unexported fields
}

MathBlock is a displayed formula on lines of its own: $$ lines or a ```math block.

func (*MathBlock) Dump added in v0.11.0

func (n *MathBlock) Dump(source []byte, level int)

func (*MathBlock) IsRaw added in v0.11.0

func (n *MathBlock) IsRaw() bool

func (*MathBlock) Kind added in v0.11.0

func (n *MathBlock) Kind() ast.NodeKind

type MathInline added in v0.11.0

type MathInline struct {
	ast.BaseInline
	Formula
}

MathInline is a formula within a paragraph: $...$, or $$...$$ displayed.

func (*MathInline) Dump added in v0.11.0

func (n *MathInline) Dump(source []byte, level int)

func (*MathInline) Kind added in v0.11.0

func (n *MathInline) Kind() ast.NodeKind

type Mermaid

type Mermaid struct {
	URL string `yaml:"url"`
}

Mermaid renders ```mermaid code blocks as diagrams. Blocks become <pre class="mermaid"> (readable source without JavaScript), and pages that have one get a module script that loads mermaid from URL and draws them, in the dark theme when the page is dark.

func (*Mermaid) ConfigKeys added in v0.2.0

func (*Mermaid) ConfigKeys() []string

func (*Mermaid) Extend

func (m *Mermaid) Extend(md goldmark.Markdown)

func (*Mermaid) Init

func (m *Mermaid) Init(cfg map[string]any, _ plugin.SiteInfo) error

func (*Mermaid) Name

func (*Mermaid) Name() string

func (*Mermaid) OnPageParsed

func (*Mermaid) OnPageParsed(p *plugin.Page) error

func (*Mermaid) OnPageRendered

func (m *Mermaid) OnPageRendered(p *plugin.Page, _ plugin.SiteView) error

type MermaidBlock

type MermaidBlock struct {
	ast.BaseBlock
}

MermaidBlock is a ```mermaid code block.

func (*MermaidBlock) Dump

func (n *MermaidBlock) Dump(source []byte, level int)

func (*MermaidBlock) IsRaw

func (n *MermaidBlock) IsRaw() bool

func (*MermaidBlock) Kind

func (n *MermaidBlock) Kind() ast.NodeKind

type ReadingTime

type ReadingTime struct {
	WordsPerMinute int `yaml:"wordsPerMinute"`
}

ReadingTime stores Data["wordCount"] and Data["readingTime"] (whole minutes, at least 1). Code blocks and raw HTML are not counted.

func (*ReadingTime) ConfigKeys added in v0.2.0

func (*ReadingTime) ConfigKeys() []string

func (*ReadingTime) Init

func (r *ReadingTime) Init(cfg map[string]any, _ plugin.SiteInfo) error

func (*ReadingTime) Name

func (*ReadingTime) Name() string

func (*ReadingTime) OnPageParsed

func (r *ReadingTime) OnPageParsed(p *plugin.Page) error

type Redirects

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

Redirects writes a meta-refresh page for every front matter alias: "/old/" becomes old/index.html, "/old.html" becomes old.html.

func (*Redirects) ConfigKeys added in v0.2.0

func (*Redirects) ConfigKeys() []string

func (*Redirects) Init

func (r *Redirects) Init(_ map[string]any, site plugin.SiteInfo) error

func (*Redirects) Name

func (*Redirects) Name() string

func (*Redirects) OnBuildComplete

func (r *Redirects) OnBuildComplete(v plugin.SiteView, out plugin.Outputs) error
type Search struct {
	MaxTextLength int `yaml:"maxTextLength"`
	// contains filtered or unexported fields
}

Search writes /search-index.json: [{url, title, headings, text}] for every page that is not a draft, with text cut to MaxTextLength bytes. headings are the page's level 2 to 6 headings as {id, text}. On a versioned site each version gets its own index, /<name>/search-index.json for older versions. Code blocks are left out of the text. The built-in theme's search box reads this index.

func (*Search) ConfigKeys added in v0.2.0

func (*Search) ConfigKeys() []string

func (*Search) Init

func (s *Search) Init(cfg map[string]any, site plugin.SiteInfo) error

func (*Search) Name

func (*Search) Name() string

func (*Search) OnBuildComplete

func (s *Search) OnBuildComplete(v plugin.SiteView, out plugin.Outputs) error

func (*Search) OnPageParsed

func (s *Search) OnPageParsed(p *plugin.Page) error

type Set

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

Set is the enabled, initialized plugins of one build, in phase order.

func Load

func Load(cfg *config.Config, site plugin.SiteInfo, extra ...plugin.Plugin) (*Set, []diag.Diagnostic)

Load enables the built-ins plus extra, initializes them and orders them by Priority, then Name. A plugin is enabled unless its section in cfg.Plugins sets enabled: false. Two plugins with the same name are an error and the later one is skipped.

func (*Set) Directives

func (s *Set) Directives() (map[string]plugin.DirectiveRenderer, []diag.Diagnostic)

Directives maps directive names to the plugins rendering them. A name claimed twice, or a built-in name, is an error.

func (*Set) Plugins

func (s *Set) Plugins() []plugin.Plugin

Plugins returns the enabled plugins in phase order.

func (*Set) Stylesheets

func (s *Set) Stylesheets() []string

Stylesheets lists the CSS files enabled plugins need, in phase order.

type Sitemap

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

Sitemap writes /sitemap.xml with the absolute URL of every page that is not a draft and belongs to the current version. It needs a baseUrl with a host.

func (*Sitemap) ConfigKeys added in v0.2.0

func (*Sitemap) ConfigKeys() []string

func (*Sitemap) Init

func (s *Sitemap) Init(_ map[string]any, site plugin.SiteInfo) error

func (*Sitemap) Name

func (*Sitemap) Name() string

func (*Sitemap) OnBuildComplete

func (s *Sitemap) OnBuildComplete(v plugin.SiteView, out plugin.Outputs) error

type Social added in v0.11.0

type Social struct {
	Image    string `yaml:"image"`
	ImageAlt string `yaml:"imageAlt"` // describes Image for screen readers
	Twitter  string `yaml:"twitter"`
	// StaticDirs are searched for a local image's size, later first.
	StaticDirs []string `yaml:"-"`
	// contains filtered or unexported fields
}

Social adds Open Graph and Twitter card tags to every page, so a link shared in a chat or social network shows the page's title, description and an image. Image is the site's card image, described by ImageAlt; a page's "image" front matter replaces it, described by its "imageAlt". Both are site paths ("/img/card.png") or absolute URLs. The tags need absolute URLs, so a site.baseUrl without a host gets a social.baseUrl warning and no tags.

func (*Social) ConfigKeys added in v0.11.0

func (*Social) ConfigKeys() []string

func (*Social) Init added in v0.11.0

func (s *Social) Init(cfg map[string]any, site plugin.SiteInfo) error

func (*Social) Name added in v0.11.0

func (*Social) Name() string

func (*Social) OnBuildComplete added in v0.11.0

func (s *Social) OnBuildComplete(v plugin.SiteView, out plugin.Outputs) error

OnBuildComplete warns about a baseUrl without a host and about card images that are not on the site.

func (*Social) OnPageRendered added in v0.11.0

func (s *Social) OnPageRendered(p *plugin.Page, v plugin.SiteView) error

OnPageRendered adds the tags to the page's <head>.

type TOC

type TOC struct {
	Default            bool
	MinLevel, MaxLevel int
}

TOC stores each page's table of contents as Data["toc"] ([]plugin.TOCEntry), from headings between MinLevel and MaxLevel. Front matter toc: true/false overrides Default.

func (*TOC) ConfigKeys added in v0.2.0

func (*TOC) ConfigKeys() []string

func (*TOC) Init

func (*TOC) Init(map[string]any, plugin.SiteInfo) error

func (*TOC) Name

func (*TOC) Name() string

func (*TOC) OnPageParsed

func (t *TOC) OnPageParsed(p *plugin.Page) error

func (*TOC) Priority

func (*TOC) Priority() int

Jump to

Keyboard shortcuts

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