docs

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFrontmatter

func ExtractFrontmatter(src string) map[string]string

ExtractFrontmatter parses YAML frontmatter from markdown content.

func HasLetters

func HasLetters(s string) bool

HasLetters checks if a string contains any letter characters.

func InjectHeadingAnchors

func InjectHeadingAnchors(html string) string

InjectHeadingAnchors post-processes rendered HTML to add anchor link buttons to headings that have id attributes.

func NormalizePagePath

func NormalizePagePath(path string) string

NormalizePagePath strips trailing "/index" from a page path for URL generation. "index" → "" "guides/index" → "guides" "guides/advanced" → "guides/advanced"

func PageURL

func PageURL(path string) string

PageURL returns the full URL for a docs page path.

func ParseKeywords

func ParseKeywords(raw string) []string

ParseKeywords splits a frontmatter `keywords:` value (comma or space separated) into a slice of trimmed keywords.

func ParseMD

func ParseMD(src string, cfg markdown.Config) (html, title string, order int, sidebar string, keywords []string)

ParseMD parses a .md file, extracting frontmatter and rendering markdown.

func ParseMDX

func ParseMDX(src string, cfg markdown.Config) (html, title string, order int, sidebar string, keywords []string)

ParseMDX parses an .mdx file, extracting frontmatter and rendering with JSX support.

func PathToTitle

func PathToTitle(path string) string

PathToTitle converts a file path or directory name to a human-readable title.

func SortPages

func SortPages(pages []Page)

SortPages sorts pages by directory, then order, then title.

func StripFrontmatter

func StripFrontmatter(src string) string

StripFrontmatter removes YAML frontmatter from markdown content.

func StripHTMLTags

func StripHTMLTags(s string) string

StripHTMLTags removes HTML tags from a string.

Types

type Breadcrumb struct {
	Label  string `json:"label"`  // display label
	URL    string `json:"url"`    // URL (empty for current page)
	IsLast bool   `json:"isLast"` // true if this is the current page
}

Breadcrumb represents a single breadcrumb item.

func BuildBreadcrumbs

func BuildBreadcrumbs(path string) []Breadcrumb

BuildBreadcrumbs returns the breadcrumb trail as a slice. Index pages (e.g. "guides/index") produce breadcrumbs ending at the directory name ("Guides") — no "Index" crumb.

type Config

type Config struct {
	ContentDir string          // relative to project root
	Root       string          // absolute project root
	MDConfig   markdown.Config // markdown rendering config
}

Config holds configuration for scanning documentation.

type Page

type Page struct {
	Path          string        `json:"path"`               // relative path like "getting-started" or "guides/advanced"
	Title         string        `json:"title"`              // from frontmatter
	Order         int           `json:"order"`              // from frontmatter, default 999
	Content       string        `json:"content"`            // rendered HTML body
	Dir           string        `json:"dir"`                // directory grouping for sidebar
	Sidebar       string        `json:"sidebar"`            // optional sidebar section override from frontmatter
	SourcePath    string        `json:"sourcePath"`         // absolute path to original .md/.mdx file
	Keywords      []string      `json:"keywords,omitempty"` // explicit search keywords from frontmatter
	CustomSidebar []SidebarItem `json:"customSidebar"`      // fully custom sidebar items (from JSON in frontmatter)
}

Page represents a single documentation page.

func Scan

func Scan(cfg Config) ([]Page, error)

Scan walks the content directory and parses all .md/.mdx files.

type SearchEntry

type SearchEntry struct {
	Title   string `json:"title"`
	Path    string `json:"path"`
	Content string `json:"content"`
}

SearchEntry represents a search index entry.

func BuildSearchIndex

func BuildSearchIndex(pages []Page) []SearchEntry

BuildSearchIndex generates a search index from documentation pages.

type SidebarItem

type SidebarItem struct {
	Title       string        `json:"title"`
	URL         string        `json:"url"`
	Active      bool          `json:"active"`
	Children    []SidebarItem `json:"children,omitempty"`
	IndexURL    string        `json:"indexURL,omitempty"`
	Collapsible bool          `json:"collapsible,omitempty"`
	Expanded    bool          `json:"expanded,omitempty"`
}

SidebarItem represents a single entry in a recursive sidebar tree. Items with Children act as expandable folder sections. Items with URL (and no Children) act as clickable links. Items with neither are plain text headers.

func BuildSidebarTree

func BuildSidebarTree(pages []Page) []SidebarItem

BuildSidebarTree builds a recursive sidebar tree from pages. Pages are grouped by their directory structure — each subdirectory becomes a nested SidebarItem with Children, supporting infinite nesting.

func EnrichSidebarItems

func EnrichSidebarItems(items []SidebarItem, currentPath string) []SidebarItem

EnrichSidebarItems pre-computes IndexURL, Collapsible, and Expanded fields for each sidebar item relative to the given currentPath. This allows the TSX renderer to use these values directly without function calls.

type TOCItem

type TOCItem struct {
	Title string `json:"title"` // displayed text
	ID    string `json:"id"`    // anchor id
	Depth int    `json:"depth"` // 2 for h2, 3 for h3
}

TOCItem represents a single heading entry in the table of contents.

func ExtractTOC

func ExtractTOC(html string) []TOCItem

ExtractTOC parses rendered HTML and extracts heading structure for the TOC sidebar.

Jump to

Keyboard shortcuts

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