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 ¶
- func Description(src string) string
- func Frontmatter(f Front) string
- func MatchExcluded(nav *Nav, relPath string) bool
- func NavPages(nav *Nav, pages []string) ([]string, error)
- func RewriteLinks(src, fromPath string, cfg Config) string
- func Slug(relPath string) string
- func Title(src string) (string, string)
- type Config
- type Front
- type Group
- type Link
- type Nav
- type Options
- type Page
- type Plan
- type SidebarGroup
- type SidebarItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Description ¶
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 ¶
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 ¶
MatchExcluded reports whether a docs/-relative path is excluded from the site by the manifest. A trailing "/**" matches the whole subtree.
func NavPages ¶
NavPages returns every docs/-relative page the manifest references, globs expanded, in sidebar order and without duplicates.
func RewriteLinks ¶
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 ¶
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 ¶
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.
type Nav ¶
type Nav struct {
}
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 ¶
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"
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 ¶
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.
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 ¶
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.