docsite

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 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 docsite transforms the canonical Markdown documentation under docs/ into the content tree the Astro + Starlight site in website/ builds from.

docs/**.md are the single source of truth and are never modified: this package only reads them. Everything it writes lives under website/ and is gitignored, regenerated by `rune docs-site-gen` (see cmd/docsite).

The transform has three parts: frontmatter derived from each page's first heading and first prose paragraph (markdown.go), link rewriting from docs/-relative paths to site paths or GitHub blob URLs (links.go, slug.go), and the sidebar built from the docs/nav.yaml manifest (nav.go, sidebar.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Description

func Description(src string) string

Description derives a one-line summary from the first prose paragraph of src: inline markup flattened to plain text, wrapped lines joined, and the result truncated to descriptionLimit on a word boundary with a trailing ellipsis. Callouts, blockquotes, code fences, tables, lists, headings and HTML blocks are skipped when locating that paragraph. Returns "" when there is no prose.

func Frontmatter

func Frontmatter(f Front) string

Frontmatter renders f as a YAML header, terminated by the closing delimiter and a blank line. Values are emitted as double-quoted scalars so ampersands, colons and quotation marks in real page titles cannot break the document.

func MatchExcluded

func MatchExcluded(nav *Nav, relPath string) bool

MatchExcluded reports whether a docs/-relative path is excluded from the site by the manifest. A trailing "/**" matches the whole subtree.

func NavPages(nav *Nav, pages []string) ([]string, error)

NavPages returns every docs/-relative page the manifest references, globs expanded, in sidebar order and without duplicates.

func RewriteLinks(src, fromPath string, cfg Config) string

RewriteLinks rewrites every Markdown link and image target in src. fromPath is the docs/-relative path of the page being transformed, used to resolve relative targets. Content inside fenced code blocks is left alone, so examples that show Markdown links keep showing them.

func Slug

func Slug(relPath string) string

Slug maps a docs/-relative Markdown path to its Starlight content slug, with no leading or trailing slash. A README.md collapses to its directory, matching Starlight's index-page handling, and names are lowercased so GRAMMAR.md lands on a predictable URL. docs/README.md maps to "", the site root.

func Title

func Title(src string) (string, string)

Title returns the text of the first level-one ATX heading in src, along with src minus that heading line. Starlight renders its own <h1> from frontmatter, so a retained heading would show the title twice. Headings inside fenced code blocks are ignored. When src has no such heading, Title returns ("", src).

Types

type Config

type Config struct {
	// BasePath is the site's base path, e.g. "/rune". A custom domain later
	// makes this "/" and nothing else changes.
	BasePath string
	// BlobBase is the GitHub blob root for files the site does not host, e.g.
	// "https://github.com/rune-task-runner/rune/blob/main".
	BlobBase string
	// EditBase is the GitHub edit root for docs/, e.g.
	// "https://github.com/rune-task-runner/rune/edit/main/docs". Each generated
	// page carries its own editUrl built from this plus its true source path,
	// which is why output paths need not mirror docs/'s layout.
	EditBase string
	// Excluded reports whether a docs/-relative page is unpublished. Links to
	// such pages become blob URLs, since a site path would 404.
	Excluded func(relPath string) bool
}

Config carries the values every rewritten link depends on. One Config is threaded through a whole generation run so the base path and blob root are each defined exactly once.

type Front

type Front struct {
	Title       string
	Description string
	// EditURL points at the real source file under docs/. It is set per page
	// because a generated path (index.md, how-to.md) does not always match its
	// source (README.md, how-to/README.md), so Starlight cannot infer it.
	EditURL string
}

Front is the Starlight frontmatter of one generated page. Starlight requires a title; the description feeds page metadata and sidebar cards.

func Transform

func Transform(src, fromPath string, cfg Config) (string, Front)

Transform converts one docs/ page into the Markdown Starlight builds from: frontmatter derived from the page's own heading and first paragraph, followed by the body with its H1 removed and every link rewritten. It returns the generated text and the frontmatter it used.

type Group

type Group struct {
	Label string
	Pages []Page
	Links []Link
}

Group is one sidebar group. It carries pages, external links, or both.

type Link struct {
	Label string
	URL   string
}

Link is one sidebar entry pointing outside the site.

type Nav struct {
	Base    string   // site base path, e.g. "/rune"
	Exclude []string // docs/-relative globs that are not published
	Groups  []Group  // sidebar groups, in order
}

Nav is the docs/nav.yaml manifest: the site's navigation structure, kept in one reviewable file so the sidebar cannot drift from the documentation set.

func ParseNav

func ParseNav(src []byte, filename string) (*Nav, error)

ParseNav parses the docs/nav.yaml manifest. It accepts a deliberately small subset of YAML — scalars, string lists, and lists of one-level mappings — and rejects everything else with a file:line error rather than guessing, so a malformed manifest can never silently produce a wrong sidebar. filename is used only in error messages.

type Options

type Options struct {
	DocsDir     string // where the canonical Markdown lives, e.g. "docs"
	NavPath     string // the navigation manifest, e.g. "docs/nav.yaml"
	OutDir      string // generated content tree, e.g. "website/src/content/docs"
	AssetsDir   string // copied assets root, e.g. "website/public"
	SidebarPath string // generated sidebar JSON
	LandingPath string // committed landing page copied to OutDir/index.mdx; "" to skip
	Config      Config
}

Options configures one generation run. Every path is relative to the repository root except DocsDir and NavPath, which are read directly.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the configuration the repository actually uses.

type Page

type Page struct {
	Path  string
	Label string
}

Page is one sidebar entry backed by a docs/ page. Path is a docs/-relative Markdown path or a glob; Label, when set, overrides the page's derived title in the sidebar only.

type Plan

type Plan struct {
	Files   map[string][]byte
	Pages   []string
	Sidebar []SidebarGroup
	// contains filtered or unexported fields
}

Plan is everything a generation run produces: file contents keyed by slash-separated path relative to the repository root, the docs/-relative pages published, and the sidebar. Building a Plan writes nothing, so tests and the -check flag can inspect a run without touching the working tree.

func Build

func Build(opts Options) (*Plan, error)

Build reads the documentation and the manifest and returns the Plan for them.

func (*Plan) Check

func (p *Plan) Check(root string) ([]string, error)

Check reports the paths where the plan and the files on disk disagree — missing, differing, or present on disk but not in the plan. It writes nothing.

func (*Plan) Write

func (p *Plan) Write(root string) error

Write clears the plan's output directories and writes every file, so a page deleted from docs/ disappears from the site.

type SidebarGroup

type SidebarGroup struct {
	Label string        `json:"label"`
	Items []SidebarItem `json:"items"`
}

SidebarGroup is one Starlight sidebar group, marshalled into website/src/generated/sidebar.json and imported by astro.config.mjs.

func Sidebar(nav *Nav, pages []string) ([]SidebarGroup, error)

Sidebar builds the Starlight sidebar from nav, resolving globs against pages (a list of docs/-relative Markdown paths). A manifest entry that matches no file is an error: a sidebar pointing at a page that does not exist would ship a 404.

type SidebarItem

type SidebarItem struct {
	Label string `json:"label,omitempty"`
	Slug  string `json:"slug,omitempty"`
	Link  string `json:"link,omitempty"`
}

SidebarItem is one entry in a group: either a content Slug or an external Link, never both. Label overrides the page's own title when set.

Jump to

Keyboard shortcuts

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