Documentation
¶
Overview ¶
Package docgenenv normalizes the process environment so documentation generators produce host-independent output.
Index ¶
- Constants
- func DecodeSourceFile(path string, v any) error
- func FrontMatter(r Route) string
- func GeneratedHeader(r Route) string
- func MarshalJSON(v any) ([]byte, error)
- func MarshalYAML(v any) ([]byte, error)
- func Prepare()
- func WriteRouteFragment(path string, routes []Route) error
- func YAMLScalar(s string) string
- type Manifest
- type ManifestIndex
- type Route
Constants ¶
const ( // ManifestSourcesDir is the directory, relative to the docs directory, // that holds the hand-edited YAML sidebar sources compiled into // manifest.json. ManifestSourcesDir = "manifest" // ManifestIndexFile is the sources file that lists the manifest versions // and the top-level section files in sidebar order. ManifestIndexFile = "index.yml" )
const GeneratedContentBanner = "<!-- DO NOT EDIT | GENERATED CONTENT -->"
GeneratedContentBanner is the HTML comment placed in the Markdown body of every generated reference page, directly below the front matter. The in-fence generatedMarker flags the page metadata as generated; this body banner flags the whole page as generated, so an editor who reads past the front matter is still warned. Both documentation generators reference this one constant so the wording cannot drift between them.
Variables ¶
This section is empty.
Functions ¶
func DecodeSourceFile ¶
DecodeSourceFile strictly decodes one sidebar source or fragment into v: YAML for .yml and .yaml files and JSON otherwise. Unknown keys, extra documents, and trailing data are errors. In YAML, a comment on the same line as a title or description is rejected, because an unquoted " #" there silently truncates the value.
func FrontMatter ¶ added in v2.37.0
FrontMatter renders r's metadata (title plus any description, icon_path, and state) as a YAML front matter block. The block opens with generatedMarker, carries the fences, and ends with the blank line that separates it from the Markdown body. Optional fields are omitted when empty.
Both documentation generators emit their front matter through this single function so a new per-page metadata field is wired in one place instead of drifting between the CLI template and the API generator. Structural manifest fields (path, children) are intentionally not mirrored here.
func GeneratedHeader ¶ added in v2.37.0
GeneratedHeader returns the full generated-page preamble: the front matter block (from FrontMatter) followed by GeneratedContentBanner and the blank line before the Markdown body. The API generator prepends this to every page so CLI and API reference pages share the same two markers; the CLI template composes the equivalent preamble inline from the frontMatter and generatedContentBanner template helpers.
func MarshalJSON ¶
MarshalJSON renders v as tab-indented JSON with a trailing newline. The Makefile runs biome over the result, so this only needs to be stable, not final. It leaves &, < and > unescaped so titles such as "Groups & Roles" stay readable in the file; both forms decode identically.
func MarshalYAML ¶
MarshalYAML renders v as YAML with two-space indentation.
func Prepare ¶
func Prepare()
Prepare clears CODER_* variables and pins the cache, config, and temp directories so generated docs don't embed the generating host's home directory.
func WriteRouteFragment ¶
WriteRouteFragment writes routes to the generated fragment at path, as YAML when the extension is .yml or .yaml and as JSON otherwise.
func YAMLScalar ¶ added in v2.37.0
YAMLScalar renders s as a YAML scalar suitable for a front matter value. Simple values are emitted verbatim. Anything YAML could misparse, such as special characters or a bare word/number YAML would otherwise resolve to a bool, null, or number, is JSON-encoded, which is valid YAML that quotes and escapes the value so it round-trips back to the original string.
Both the CLI and API documentation generators share this helper so their front-matter escaping cannot silently diverge.
Types ¶
type Manifest ¶ added in v2.37.0
type Manifest struct {
Versions []string `json:"versions,omitempty"`
Routes []Route `json:"routes,omitempty"`
}
Manifest describes the entire documentation index (docs/manifest.json).
func BuildManifest ¶
BuildManifest reads the sidebar sources in dir, splices every children_from fragment into its route, and validates the result. When docsDir is not empty, every route path must name an existing file under it. It fails on any file in dir that nothing references, so a section can't silently drop out of the sidebar.
func LoadManifestSources ¶
LoadManifestSources reads the sidebar sources in dir: the index plus one top-level route per section file, with every include resolved. Routes that set children_from are returned unresolved, so their Children hold only the curated metadata overlays. The doc generators use this to read curated metadata without depending on the generated fragments they are about to rewrite.
func (*Manifest) FindRoute ¶ added in v2.37.0
FindRoute walks the manifest, following titles as a breadcrumb from the top-level routes, and returns a pointer to the matching route (or nil if any title in the path has no match). The returned pointer aliases the manifest, so mutating it (for example, replacing Children) updates the manifest in place.
Both documentation generators resolve their target route through this single traversal so the route they read metadata from and the route they rewrite cannot drift apart.
type ManifestIndex ¶
type ManifestIndex struct {
Versions []string `yaml:"versions"`
Sections []string `yaml:"sections"`
}
ManifestIndex is the decoded ManifestIndexFile. Its field order is the key order enforced in the source file.
type Route ¶ added in v2.37.0
type Route struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
IconPath string `json:"icon_path,omitempty" yaml:"icon_path,omitempty"`
State []string `json:"state,omitempty" yaml:"state,omitempty"`
// ChildrenFrom names a generated fragment, relative to the sources
// directory, that supplies this route's children. It exists only in the
// sources; BuildManifest replaces it with the fragment's routes.
ChildrenFrom string `json:"-" yaml:"children_from,omitempty"`
// Include names another source file, relative to the sources directory,
// that holds this child route. It exists only in the sources, where an
// include entry sets no other key; the loader replaces the entry with the
// route in the named file.
Include string `json:"-" yaml:"include,omitempty"`
Children []Route `json:"children,omitempty" yaml:"children,omitempty"`
}
Route is an individual page object in the docs manifest.json. Per-page metadata (title, description, icon_path, state) is mirrored into page front matter by the doc generators; the structural fields (path, children) stay in the manifest.
The same type decodes the YAML sidebar sources under docs/manifest, so the field order here is the key order enforced in both the sources and the compiled manifest.json.