pages

package
v0.0.0-...-b2f9c62 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package pages loads user-authored markdown files from a directory and renders them as additional Compass pages.

Files are read on demand at request time so updating a file is reflected on the next page load without restarting the server.

Layout

The configured directory may contain top-level *.md files and/or sub-directories of *.md files. Each top-level file becomes /pages/{slug}. Each sub-directory becomes its own nav dropdown with URLs of the form /pages/{section}/{slug}. Sub-directory names may be prefixed with a numeric order (01-administration) which is stripped from the displayed title.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader knows how to list and render pages from a directory.

func NewLoader

func NewLoader(dir string) *Loader

NewLoader returns a Loader rooted at dir. An empty dir yields no pages.

func (l *Loader) Backlinks(serviceID string, services []compass.Service) ([]Page, error)

Backlinks returns every page whose body mentions serviceID, either via a `[[id]]` / `[[name]]` wiki-link or one of the service-targeting shortcodes (`{{< service id=X >}}`, `{{< panel service=X >}}`). Walks the pages directory once per call — at homelab scale (dozens of files) the cost is negligible and keeps the "edit a page, see it next request" promise intact.

Pass the same services slice you'd pass to Get; the lookup matches by ID or by display name (case-insensitive).

func (*Loader) Enabled

func (l *Loader) Enabled() bool

Enabled reports whether a pages directory was configured.

func (*Loader) Get

func (l *Loader) Get(
	section, slug string,
	services []compass.Service,
) (Page, template.HTML, []TOCEntry, error)

Get loads, parses, and renders a single page. Pass section="" for a top-level page. Services are passed in for shortcode expansion (see {{< services tag=foo >}}); pass nil if shortcode results aren't needed. Returns the rendered HTML and the page's heading TOC.

func (*Loader) Sections

func (l *Loader) Sections() ([]Section, error)

Sections returns the page index grouped by sub-directory. The result is sorted: top-level pages (if any) come first under the "Pages" label, then sub-directory sections in lexical order of the on-disk dir name (with any numeric prefix preserved for ordering).

type Page

type Page struct {
	Slug      string // file slug (without .md)
	Section   string // section slug; "" for top-level pages
	Title     string
	Order     int
	Tags      []string
	UpdatedAt time.Time // file mtime; zero when stat fails
}

Page describes one markdown page.

func (Page) URL

func (p Page) URL() string

URL returns the URL for the page, accounting for whether it's nested.

type Section

type Section struct {
	Slug  string // "" for top-level
	Title string // displayed in the nav (top-level uses "Pages")
	Order int
	Pages []Page
}

Section is a group of pages, either the implicit top-level group ("") or a sub-directory.

type TOCEntry

type TOCEntry struct {
	Level  int // 2 for h2, 3 for h3, etc.
	Text   string
	Anchor string // matches the auto-heading-id on the rendered heading
}

TOCEntry is one heading in a page's table of contents.

Jump to

Keyboard shortcuts

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