nav

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package nav implements the filesystem walker, nav tree builder, and core data types used throughout kwelea.

The primary entry point is NewSite, which reads a config.Config, walks the docs directory (or follows the manual [nav] order defined in kwelea.toml), parses YAML-style frontmatter from every Markdown file, strips numeric filename prefixes, derives URL slugs, and returns a fully populated Site whose pages are linked in prev/next order.

Exported types — Site, NavSection, NavItem, Page, TocItem — are the data model that the builder and server packages depend on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinkPrevNext

func LinkPrevNext(pages []*Page)

LinkPrevNext sets Prev and Next on each page in the slice, which must already be in nav order (output of FlattenNav).

Types

type Frontmatter

type Frontmatter struct {
	Title       string
	Description string
	Draft       bool
}

Frontmatter holds the YAML front matter fields recognised by kwelea. All fields are optional; their zero values are sensible defaults.

type NavItem struct {
	Title  string
	Path   string
	Active bool
}

NavItem is a single entry in the sidebar nav. Active is set by the renderer when this item matches the current page.

type NavSection struct {
	Label string
	Items []NavItem
}

NavSection is a labelled group of pages in the sidebar. Label is empty ("") for root-level pages that have no section heading.

func Build

func Build(pages []*Page, navEntries []config.NavEntry) ([]NavSection, error)

Build creates the navigation tree from the discovered pages. If navEntries is non-empty (manual [nav] sections from kwelea.toml) it uses those; otherwise it builds the nav automatically from the filesystem. An error is returned only when a manual nav ref is ambiguous.

type Page

type Page struct {
	Title                string
	TitleFromFrontmatter bool // true when Title came from frontmatter; false when derived from filename
	Description          string
	Path                 string        // canonical URL path, e.g. /getting-started/
	FilePath             string        // source .md file, relative to docs_dir
	HTML                 template.HTML // filled by parser (Phase 3)
	TOC                  []TocItem     // filled by parser (Phase 3)
	Prev                 *Page
	Next                 *Page
	Draft                bool
}

Page holds all data needed to render a single documentation page. HTML and TOC are zero until Phase 3 fills them in via the parser.

func FlattenNav

func FlattenNav(sections []NavSection, pages []*Page) []*Page

FlattenNav returns all unique Pages from the nav sections in order. The result is used to assign Prev/Next links.

func WalkDocs

func WalkDocs(docsDir string) ([]*Page, error)

WalkDocs discovers all non-draft .md files under docsDir and returns them as Page values with metadata populated. HTML and TOC are left empty until Phase 3 fills them in via the Markdown parser.

Files are returned in the order filepath.WalkDir visits them — lexical order within each directory. The nav builder re-sorts within sections to put index.md pages first.

type Site

type Site struct {
	Title        string
	Version      string
	BaseURL      string
	BasePath     string // URL path prefix derived from BaseURL, e.g. "/kwelea" or ""
	Repo         string
	RepoPlatform string // "github", "gitlab", or "" for unknown/not set
	BuildCfg     config.BuildConfig
	ServeCfg     config.ServeConfig
	ThemeCfg     config.ThemeConfig
	Nav          []NavSection // full nav tree, built by this package
	Pages        []*Page      // flat ordered list for prev/next linking
}

Site is the root context passed to every template render. It is built once per build and then treated as read-only.

func NewSite

func NewSite(cfg *config.Config) (*Site, error)

NewSite runs the full Phase 2 pipeline: walk docs_dir, build the nav tree, flatten into a page list, and link prev/next.

type TocItem

type TocItem struct {
	ID    string
	Text  string
	Level int // 2 (h2) or 3 (h3)
}

TocItem is a heading entry in the in-page table of contents.

Jump to

Keyboard shortcuts

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