{"modulePath":"github.com/Pinta365/tryck","version":"v0.12.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\nPackage plugin is tryck's public plugin API.\n\nPlugins are compiled into a custom binary with tryck.Main (package pkg/tryck). Every plugin implements Plugin plus any of the phase interfaces below. A build parses every page, then renders every page, then finalizes once; each phase calls the plugins that implement it, ordered by Priority (lower first, default 100) and then by Name.\n\nPlugins see copies and read-only views, never the build's own state.\n\n## Constants\n\n```go\nconst DefaultPriority = 100\n```\nDefaultPriority applies to plugins that do not implement Ordered.\n\n## Types\n\n```go\ntype ConfigKeys interface{ ConfigKeys() []string }\n```\nConfigKeys is implemented by plugins that declare their config keys, so typos in their section produce config.unknownKey warnings. \"enabled\" is always allowed.\n\n```go\ntype Diagnostic struct {\n\tSeverity Severity\n\tLine     int\n\tCol      int\n\tCode     string // stable id, e.g. \"link.broken\"\n\tMessage  string\n}\n```\nDiagnostic is a problem a plugin reports about a page. Line and Col are 1-based file positions, or 0 when unknown.\n\n```go\ntype Directive struct {\n\tName  string\n\tTitle string            // from :::name[title]\n\tAttrs map[string]string // from {key=value .class #id}; class and id included\n}\n```\nDirective describes a ::: block for a DirectiveRenderer.\n\n```go\ntype DirectiveRenderer interface {\n\t// DirectiveNames lists the directive names this plugin renders.\n\tDirectiveNames() []string\n\t// RenderDirective writes the opening HTML (entering) or closing HTML\n\t// (!entering) of d. The directive's Markdown content is rendered\n\t// between the two calls.\n\tRenderDirective(w io.Writer, d Directive, entering bool) error\n}\n```\nDirectiveRenderer renders ::: directives with names tryck does not know. Registered names do not produce directive.unknown warnings.\n\n```go\ntype Finalizer interface {\n\tOnBuildComplete(s SiteView, out Outputs) error\n}\n```\nFinalizer runs once, after every page is rendered. It may add output files.\n\n```go\ntype FrontMatter struct {\n\tTitle       string         `yaml:\"title\" json:\"title,omitempty\"`\n\tDescription string         `yaml:\"description\" json:\"description,omitempty\"`\n\tLayout      string         `yaml:\"layout\" json:\"layout,omitempty\"`\n\tDate        time.Time      `yaml:\"date\" json:\"date,omitempty\"`\n\tDraft       bool           `yaml:\"draft\" json:\"draft,omitempty\"`\n\tWeight      int            `yaml:\"weight\" json:\"weight,omitempty\"`     // nav ordering\n\tNavTitle    string         `yaml:\"navTitle\" json:\"navTitle,omitempty\"` // shorter sidebar label\n\tTOC         *bool          `yaml:\"toc\" json:\"toc,omitempty\"`           // nil = config default\n\tSlug        string         `yaml:\"slug\" json:\"slug,omitempty\"`         // overrides URL segment\n\tAliases     []string       `yaml:\"aliases\" json:\"aliases,omitempty\"`   // old URLs -\u003e redirect pages\n\tParams      map[string]any `yaml:\",inline\" json:\"params,omitempty\"`\n}\n```\nFrontMatter is the YAML header of a page.\n\n```go\ntype MarkdownExtender interface {\n\tExtend(m goldmark.Markdown)\n}\n```\nMarkdownExtender extends the goldmark instance (parsers, AST transformers, renderers). It runs once per build, before parsing.\n\n```go\ntype NavNode struct {\n\tTitle    string\n\tURL      string // \"\" for a folder without an index page\n\tDraft    bool\n\tSection  bool // a folder, possibly with an index page\n\tChildren []*NavNode\n\tActive   bool // the page being rendered (per-page views only)\n\tInPath   bool // the active page or one of its ancestors\n}\n```\nNavNode is an entry in the navigation tree. The tree is shared and must not be modified.\n\n```go\ntype Ordered interface{ Priority() int }\n```\nOrdered sets the order within a phase. Lower runs first; default 100.\n\n```go\ntype Outputs interface {\n\t// Add writes data to path, relative to outputDir (\"sitemap.xml\").\n\t// It fails if the path is invalid or already produced.\n\tAdd(path string, data []byte) error\n\t// Report records a diagnostic that is not about one page.\n\tReport(d Diagnostic)\n}\n```\nOutputs collects extra output files and site-wide diagnostics.\n\n```go\ntype Page struct {\n\tSourcePath string         // relative to its version's content directory, forward slashes\n\tVersion    string         // the page's version; \"\" on an unversioned site\n\tURL        string         // \"/docs/setup/\"\n\tFront      FrontMatter    // typed front matter\n\tData       map[string]any // plugin-added values, e.g. \"readingTime\", \"toc\"\n\tAST        ast.Node       // goldmark document; read-only for plugins\n\tSource     []byte         // body without front matter\n\tBodyLine   int            // file line on which Source starts\n\tHTML       []byte         // the rendered page, set after the layout runs\n\tDiags      Reporter       // per-page diagnostics\n}\n```\nPage is a page being built. A plugin receives only the page it is called for.\n\n```go\nfunc (p *Page) LineAt(offset int) int\n```\nLineAt converts a byte offset in Source to a 1-based file line.\n\n```go\ntype PageInfo struct {\n\tSourcePath  string\n\tVersion     string // \"\" on an unversioned site\n\tTitle       string\n\tNavTitle    string\n\tDescription string\n\tURL         string\n\tDate        time.Time\n\tLastUpdated time.Time // the file's last commit date, with build.lastUpdated; zero otherwise\n\tDraft       bool\n\tWeight      int\n\tTitleInBody bool           // the body has its own h1, so layouts skip theirs\n\tAliases     []string       // old URLs that redirect here\n\tParams      map[string]any // front matter keys tryck does not know\n\tData        map[string]any // plugin-added values as of the end of parsing\n}\n```\nPageInfo is a read-only copy of a page for templates and SiteView. Changing it does not affect the build.\n\n```go\ntype PageParser interface {\n\tOnPageParsed(p *Page) error\n}\n```\nPageParser runs per page and in parallel, after the page's Markdown is parsed. It may modify its own page only, and must not modify p.AST: tryck dev reuses parsed ASTs between builds. Change the document with a MarkdownExtender (an AST transformer) instead.\n\n```go\ntype PageRenderer interface {\n\tOnPageRendered(p *Page, s SiteView) error\n}\n```\nPageRenderer runs per page and in parallel, after the layout has been executed. It may modify p.HTML and p.Data. The site is read-only.\n\n```go\ntype Plugin interface {\n\t// Name is the plugin's config key under \"plugins:\", e.g. \"readingTime\".\n\tName() string\n\t// Init receives the plugin's own config section (nil if absent) and\n\t// the site settings. It runs once per build before any phase.\n\tInit(cfg map[string]any, site SiteInfo) error\n}\n```\nPlugin is implemented by every plugin.\n\n```go\ntype Reporter interface {\n\tReport(d Diagnostic)\n}\n```\nReporter receives diagnostics for one page. It is safe for concurrent use.\n\n```go\ntype Severity int\n```\nSeverity of a Diagnostic.\n\n```go\nconst (\n\tInfo Severity = iota\n\tWarning\n\tError\n)\n```\n\n```go\ntype SiteInfo struct {\n\tTitle       string\n\tDescription string\n\tBaseURL     string // always ends in \"/\"\n\tLanguage    string\n\tVersion     string // the current version's name; \"\" on an unversioned site\n\tDev         bool   // building for tryck dev\n}\n```\nSiteInfo holds site-wide settings.\n\n```go\ntype SiteView interface {\n\tPages() []*PageInfo // sorted by URL\n\tPageByURL(url string) (*PageInfo, bool)\n\tNav() *NavNode\n\tHasAnchor(url, id string) bool\n\t// HasFile reports whether a site path (\"/img/logo.png\", \"/docs/\")\n\t// is served: a page, a copied asset or static file, or a generated\n\t// file added so far.\n\tHasFile(sitePath string) bool\n\tConfig() SiteInfo\n}\n```\nSiteView is a read-only view of the built site. It is safe for concurrent use.\n\n```go\ntype Stylesheets interface {\n\tStylesheets() []string\n}\n```\nStylesheets lists site paths of CSS files a plugin needs on every page, such as \"/css/chroma.css\". Layouts link them in \\\u003chead\u003e.\n\n```go\ntype TOCEntry struct {\n\tLevel    int\n\tID       string\n\tText     string\n\tChildren []TOCEntry\n}\n```\nTOCEntry is a heading in a page's table of contents, stored by the toc plugin as Data\\[\"toc\"] (\\[]TOCEntry).\n\n","path":"github.com/Pinta365/tryck/pkg/plugin","name":"plugin","synopsis":"Package plugin is tryck's public plugin API.","isRedistributable":true}
