build

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 59 Imported by: 0

Documentation

Overview

Package build orchestrates the full site build pipeline.

Index

Constants

View Source
const DefaultPageCacheCapacity = 512

Variables

This section is empty.

Functions

func BundleEmbeddedJS

func BundleEmbeddedJS(embeddedFS fs.FS, devMode bool) ([]byte, string, error)

BundleEmbeddedJS concatenates all JS files under assets/js/ in the embedded theme FS into a single bundle, wrapping each in an IIFE. In production mode the bundle is minified via esbuild. Returns the bundled content and a filename (fingerprinted in production, plain in dev).

func BundleThemeJS added in v1.0.0

func BundleThemeJS(projectDir, themeName string, devMode bool) ([]byte, string, error)

BundleThemeJS concatenates all JS files under themes/{themeName}/assets/js/ into a single bundle, wrapping each in an IIFE. Returns ("", "", nil) if the theme has no assets/js/ directory, allowing fallback to BundleEmbeddedJS.

func ContentHash

func ContentHash(content string) string

ContentHash returns the sha256 hex digest of raw content.

func KnownPluginNames

func KnownPluginNames(projectDir string) []string

KnownPluginNames returns the union of all valid plugin names from the Go-side registry, subpackage plugins, client-side manifest, and external plugins discovered under {projectDir}/plugins. An empty projectDir skips external discovery.

func PageOutputPath

func PageOutputPath(relPermalink string) string

PageOutputPath converts a RelPermalink to an output file path. "/" → "index.html" "/docs/intro/" → "docs/intro/index.html" "/404.html" → "404.html"

func ReservedPluginNames added in v1.2.0

func ReservedPluginNames(projectDir string) []string

ReservedPluginNames returns KnownPluginNames plus the deprecated kebab-case alias of every snake_case name. An external plugin may not claim a legacy spelling: the config alias layer still resolves it to the canonical plugin, and the kebab-ized vendor asset prefix would collide with the snake original.

func WriteEmbeddedAssets

func WriteEmbeddedAssets(embeddedFS fs.FS, outputDir string, tracker *OutputTracker, skipPrefixes []string) error

WriteEmbeddedAssets walks the `assets/` subtree inside the given embedded theme filesystem and writes every file to outputDir/assets/. Files under any of the skipPrefixes are skipped (used to exclude bundled JS). It is a no-op when the `assets/` directory is absent.

func WriteEmbeddedCSS

func WriteEmbeddedCSS(outputDir string, css string, filename string, tracker *OutputTracker) error

WriteEmbeddedCSS writes the embedded CSS bundle to outputDir/assets/css/<filename>.

func WriteThemeAssets added in v1.0.0

func WriteThemeAssets(projectDir, themeName, outputDir string, tracker *OutputTracker, skipPrefixes []string) error

WriteThemeAssets walks the assets/ subtree inside an external theme directory and copies every file to outputDir/assets/. Files under any of the skipPrefixes are skipped (used to exclude bundled JS).

Types

type BuildError

type BuildError struct {
	Type    string // "template", "frontmatter", "markdown", "build"
	File    string // relative file path
	Line    int    // 1-based line number
	Col     int    // 1-based column number
	Message string // error message
	Frame   string // ±3 lines of source context
}

BuildError holds structured information about a build failure.

func ParseBuildError

func ParseBuildError(err error, projectDir string) *BuildError

ParseBuildError extracts structured error info from a build error. Returns nil if the error cannot be parsed into a structured form.

type BuildOptions

type BuildOptions struct {
	ProjectDir      string
	Config          *config.SiteConfig
	ThemeConfig     *engine.ThemeConfig
	EmbeddedFS      fs.FS
	DevMode         bool   // Skip heavy optimizations during serve (image processing, minification, etc.)
	CheckSyntax     bool   // When true, run fenced-block syntax checking during markdown rendering
	PluginAssetsDir string // If set, recompute plugin client bundles from disk (theme-dev mode)
}

BuildOptions provides the inputs for creating a SiteBuilder.

type CacheEntry

type CacheEntry struct {
	ContentHash    string                 `json:"content_hash"`
	HTML           string                 `json:"html"`
	Headings       []engine.Heading       `json:"headings"`
	HasCodeBlocks  bool                   `json:"has_code_blocks,omitempty"`
	HasImages      bool                   `json:"has_images,omitempty"`
	Links          []engine.CollectedLink `json:"links,omitempty"`
	PendingAnchors []CachedAnchorCheck    `json:"pending_anchors,omitempty"`
	Refs           []CachedLinkRef        `json:"refs,omitempty"`
}

CacheEntry holds the cached result of rendering a page's markdown.

type CachedAnchorCheck added in v1.0.0

type CachedAnchorCheck struct {
	TargetPermalink    string         `json:"target_permalink"`
	TargetRelPermalink string         `json:"target_rel_permalink,omitempty"`
	Fragment           string         `json:"fragment"`
	RawHref            string         `json:"raw_href"`
	Kind               links.LinkKind `json:"kind"`
	Resolved           string         `json:"resolved"`
}

CachedAnchorCheck holds the content-derived fields of a pending anchor check (links.PendingAnchorCheck) that are safe to persist across builds. Page-derived fields (source file, from/target page pointers, dimension) are reconstructed from the live page at cache-hit time; see replayPendingAnchors in helpers.go.

type CachedLinkRef added in v1.0.0

type CachedLinkRef struct {
	RawDest            string           `json:"raw_dest"`
	Kind               links.LinkKind   `json:"kind"`
	Resolved           string           `json:"resolved"`
	TargetPermalink    string           `json:"target_permalink,omitempty"`
	TargetRelPermalink string           `json:"target_rel_permalink,omitempty"`
	Fragment           string           `json:"fragment,omitempty"`
	Status             links.LinkStatus `json:"status"`
}

CachedLinkRef holds the content-derived fields of a recorded link ref (links.LinkRef) that are safe to persist across builds. On a cache hit the snapshot is first verified against the live page index (see entryStale in helpers.go); any divergence demotes the hit to a miss so the page re-renders with fresh URLs instead of replaying stale results.

type CheckOptions

type CheckOptions struct {
	External     bool   // enable external URL probing
	Strict       bool   // override all policies to "error"
	ReportFormat string // override report format ("pretty" | "json" | "github-actions")
}

CheckOptions controls the behavior of the Check method.

type CheckResult

type CheckResult struct {
	PageCount int
	LinkCount int
	Lanes     int
	HasErrors bool
	Findings  []links.Finding
	Warnings  []engine.ValidationWarning
	Output    string // formatted report output
	Summary   string
	Duration  time.Duration
}

CheckResult holds the outcome of a link-check-only run.

type Minifier

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

Minifier wraps tdewolff/minify for HTML minification.

func NewMinifier

func NewMinifier() *Minifier

NewMinifier creates a Minifier configured for HTML.

func (*Minifier) MinifyHTML

func (mn *Minifier) MinifyHTML(input []byte) []byte

MinifyHTML minifies HTML content. Returns the original on error (non-fatal).

type OutputTracker

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

OutputTracker records every file written during a build so orphaned files from previous builds can be pruned without a full RemoveAll.

func NewOutputTracker

func NewOutputTracker(sizeHint int) *OutputTracker

NewOutputTracker creates an OutputTracker pre-sized for the expected number of output files.

func (*OutputTracker) Prune

func (t *OutputTracker) Prune(outputDir string) error

Prune walks outputDir and removes any file not in the written set, then removes empty directories bottom-up.

func (*OutputTracker) Track

func (t *OutputTracker) Track(path string)

Track records a path as written. Thread-safe.

func (*OutputTracker) TrackBatch

func (t *OutputTracker) TrackBatch(paths []string)

TrackBatch records multiple paths as written in a single lock acquisition.

type PageCache

type PageCache struct {
	Dir string
	// contains filtered or unexported fields
}

PageCache is a two-layer (in-memory LRU + filesystem) content-addressed cache for rendered markdown. Safe for concurrent use.

func NewPageCache

func NewPageCache(projectDir string) *PageCache

NewPageCache creates a PageCache with the default capacity.

func (*PageCache) Get

func (c *PageCache) Get(hash string) *CacheEntry

Get retrieves a cached entry by content hash. Checks in-memory LRU first, then falls through to filesystem.

The returned *CacheEntry (including its Headings/Links slices) is shared with the in-memory LRU and, on a hit, with every other caller of the same hash. Callers MUST treat it as read-only: mutating it (e.g. appending to Headings) would corrupt the cache and other pages. Copy before mutating if needed.

func (*PageCache) Put

func (c *PageCache) Put(hash string, entry *CacheEntry)

Put stores a cache entry in both in-memory LRU and filesystem.

type RenderedPage

type RenderedPage struct {
	Page    *engine.Page
	HTML    []byte
	OutPath string // relative to output dir (e.g., "docs/intro/index.html")
}

RenderedPage holds a rendered page and its output path.

type SiteBuilder

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

SiteBuilder orchestrates the full six-phase build pipeline.

func NewSiteBuilder

func NewSiteBuilder(opts BuildOptions) *SiteBuilder

NewSiteBuilder creates a SiteBuilder with all dependencies initialized.

func (*SiteBuilder) Build

func (b *SiteBuilder) Build() (*engine.BuildResult, error)

Build executes the full six-phase pipeline and writes output to disk.

func (*SiteBuilder) Check

func (b *SiteBuilder) Check(opts CheckOptions) (*CheckResult, error)

Check runs the build pipeline through link validation and returns the report without rendering templates or writing HTML to disk.

func (*SiteBuilder) ContentRebuild

func (b *SiteBuilder) ContentRebuild(changedPaths []string) (*engine.BuildResult, error)

ContentRebuild performs an incremental rebuild for content-only changes. It re-parses only the changed files, patches them into the existing collections, and renders/writes only the dirty pages. Falls back to full Build() on edge cases.

func (*SiteBuilder) RefreshThemeCSS added in v1.3.0

func (b *SiteBuilder) RefreshThemeCSS() error

RefreshThemeCSS reassembles the theme CSS bundle from disk and rewrites it in the output directory, without running the build pipeline. Used by the dev server's theme-CSS fast path; requires a prior successful Build so the output directory and bundle filename are known.

func (*SiteBuilder) Validate

func (b *SiteBuilder) Validate() (*ValidateResult, error)

Validate runs phases 1-4 (Initialize, Discover, Parse, Assemble) without rendering or writing.

type ValidateResult

type ValidateResult struct {
	PageCount   int
	Collections int
	Warnings    []engine.ValidationWarning
	Pages       []*engine.Page
	Duration    time.Duration
}

ValidateResult holds the outcome of a validation run (no rendering or writing).

type Writer

type Writer struct {
	OutputDir  string
	ProjectDir string
	Tracker    *OutputTracker
}

Writer handles the Write phase: outputting HTML, aliases, and static files.

func (*Writer) Write

func (w *Writer) Write(pages []RenderedPage, aliases map[string]string) (int, error)

Write outputs all rendered pages, alias redirects, and static files. Returns the number of static files copied.

Jump to

Keyboard shortcuts

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