Documentation
¶
Overview ¶
Package sitegen builds a documentation site from a Go module's own source: the package comments, the exported API, the tested examples, and a guide of markdown pages. The site is the by-product of writing ordinary, documented Go; nothing is written twice.
What the site is made of ¶
Four sources, each optional except the source itself:
- README.md at the module root is the front page.
- Every package's doc comment (doc.go by convention) is its overview.
- Every exported identifier's doc comment is its reference entry, rendered with the signature printed from the syntax tree.
- Every Example function in a _test.go file is shown with its code and its Output block — go test proves the output, so the example cannot rot.
- Markdown files under guide/ (or the directory named in Config) are the narrative pages, ordered by their front matter.
The discipline it asks for ¶
The standard one, the one pkg.go.dev already expects: an exported name carries a comment that begins with the name; a package carries a comment; anything worth showing carries an example with output. Check reports what is missing so a test can refuse a release that forgets.
The theme ¶
Pages wear system.css from a CDN tag and nothing else; the generator ships no stylesheet and no script of its own. The shell is the engine's page grid: a header, a rail of sections, the page, an "On this page" aside, previous and next.
Index ¶
Constants ¶
const ( DefaultTheme = "https://cdn.jsdelivr.net/gh/Deufel/system-css@v0.6.0/static/system.css" DefaultHighlight = "https://cdn.jsdelivr.net/gh/Deufel/system-css@v0.6.0/static/highlight.css" DefaultHighlightJS = "https://cdn.jsdelivr.net/gh/Deufel/system-css@v0.6.0/static/highlight.js" )
DefaultTheme — the engine at a tag; a site pins one and moves on purpose.
Variables ¶
This section is empty.
Functions ¶
func DocHTML ¶
DocHTML renders a Go doc comment (the go/doc/comment syntax: headings, lists, code blocks, links) to HTML.
Types ¶
type Config ¶
type Config struct {
Root string // the module's directory (holds go.mod)
Out string // the site's directory (created; index.html and the pages)
Title string // the site's name; the module's last path element when empty
Tagline string // a few words under the title
Repo string // the repository URL, linked from the header
Guide string // the markdown pages' directory relative to Root; "guide" when empty; absent is fine
// Theme is the engine stylesheet's URL; the pinned system.css tag when
// empty. Highlight is its syntax companion ("" = the tag's).
Theme, Highlight, HighlightJS string
}
Config names the module and where its site goes.
type Example ¶
type Example struct {
Name string // the example's full name (ExampleRun_backup)
For string // the symbol it documents ("" = the package)
Suffix string // the part after the underscore
Doc string
Code string
Output string
}
Example is one Example function: what it shows, its code, its output.
type Package ¶
type Package struct {
ImportPath string
Name string
Dir string // relative to the module root
Doc string // the package comment, raw
Synopsis string // its first sentence
Consts []Symbol // exported, grouped as declared
Vars []Symbol
Types []Type
Funcs []Symbol // package-level functions
Examples []Example
}
Package is one Go package as the site reads it.
type Page ¶
type Page struct {
Path string // relative to Out ("index.html", "guide/start.html", "pkg/migrate.html")
Title string
Section string // "" (home) · "guide" · "pkg"
Order int
Body string // the rendered HTML inside the measure
}
Page is one rendered page of the site.
type Problem ¶
type Problem struct {
Package string
Kind string // "package-doc" · "symbol-doc" · "example" · "link"
Name string
}
Problem is one thing the module's documentation lacks.
func Check ¶
Check reads the module and reports what the discipline asks for and the source lacks: a package without a comment, an exported symbol without one, a package-level function with no example. A test asserts the list is empty; the strictness is the caller's — filter by Kind for the level a project keeps.
func CheckLinks ¶
CheckLinks walks the built site and reports every relative link that names a file the site lacks.