docgenenv

package
v2.39.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 13 Imported by: 1 module, 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 docgenenv normalizes the process environment so documentation generators produce host-independent output.

Index

Constants

View Source
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"
)
View Source
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

func DecodeSourceFile(path string, v any) error

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

func FrontMatter(r Route) string

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

func GeneratedHeader(r Route) string

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

func MarshalJSON(v any) ([]byte, error)

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

func MarshalYAML(v any) ([]byte, error)

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

func WriteRouteFragment(path string, routes []Route) error

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

func YAMLScalar(s string) string

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

func BuildManifest(dir, docsDir string) (*Manifest, error)

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

func LoadManifestSources(dir string) (*Manifest, error)

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

func (m *Manifest) FindRoute(titles ...string) *Route

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.

Jump to

Keyboard shortcuts

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