content

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 17 Imported by: 0 modules, 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 content discovers source files and models pages: front matter, URL mapping and titles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetPath

func AssetPath(rel string) string

AssetPath maps a non-Markdown file in contentDir to its output path, stripping numeric prefixes from its directories like URLFor does.

func FirstH1

func FirstH1(doc ast.Node, source []byte) string

FirstH1 returns the text of the first level-1 heading in doc, or "".

func Humanize

func Humanize(s string) string

Humanize turns "getting-started" into "Getting started".

func IsSectionIndex

func IsSectionIndex(rel string) bool

IsSectionIndex reports whether a content file is a section index page (_index.md or index.md).

func NumericPrefix

func NumericPrefix(seg string) int

NumericPrefix returns the ordering prefix of a path segment ("02-setup" -> 2), or -1 if StripNumericPrefix would not remove one.

func OutputPath

func OutputPath(url string) string

OutputPath maps a page URL to the file it is written to, relative to outputDir: "/docs/setup/" -> "docs/setup/index.html".

func PlainText

func PlainText(n ast.Node, source []byte) string

PlainText concatenates the text content of n's inline descendants.

func SplitFrontMatter

func SplitFrontMatter(src []byte) (fm, body []byte, bodyLine int, err error)

SplitFrontMatter separates a leading "---" delimited YAML block from the body. bodyLine is the 1-based file line on which the body starts, used to map body positions back to the file. If src has no front matter, fm is nil and body is src. An opening "---" without a closing one is an error.

func StripNumericPrefix

func StripNumericPrefix(seg string) string

StripNumericPrefix removes an ordering prefix like "01-" from a path segment. A segment that would become empty, or that starts with a YYYY-MM-DD date (a dated blog post), is returned unchanged.

func TitleFromPath

func TitleFromPath(rel string) string

TitleFromPath derives a title from a content path: the file name, or the directory name for section indexes, without numeric prefix, with dashes and underscores as spaces and the first letter capitalized. The root index yields "".

func URLFor

func URLFor(rel, slug string) string

URLFor maps a Markdown file path, relative to contentDir and using forward slashes, to its clean URL:

docs/setup.md      -> /docs/setup/
docs/_index.md     -> /docs/
index.md           -> /
01-intro.md        -> /intro/

A non-empty slug replaces the last URL segment. The root index page ignores the slug.

func WalkFiles

func WalkFiles(root string, fn func(path, rel string)) error

WalkFiles calls fn for every regular file under root with its path relative to root. A missing root yields nothing.

Types

type Asset

type Asset struct {
	Src     string // absolute or root-relative path on disk
	Rel     string // relative to contentDir, forward slashes
	OutPath string // relative to outputDir
}

Asset is a non-Markdown file inside contentDir, copied next to pages.

type FrontMatter

type FrontMatter = plugin.FrontMatter

FrontMatter is the YAML header of a page.

func ParseFrontMatter

func ParseFrontMatter(file string, fm []byte) (FrontMatter, []diag.Diagnostic)

ParseFrontMatter decodes fm. Diagnostics point into file, with YAML line numbers shifted by the opening fence.

type Page

type Page struct {
	plugin.Page
	File    string   // relative to project root, for diagnostics
	OutPath string   // relative to outputDir: "docs/setup/index.html"
	Title   string   // front matter title, first h1, or file name
	HasH1   bool     // the body contains a level-1 heading
	Hash    [32]byte // SHA-256 of the source file

	LastUpdated time.Time // last commit date, with build.lastUpdated
}

Page is one Markdown source file and everything derived from it. The embedded plugin.Page is the part plugins see.

type Sources

type Sources struct {
	Pages  []string // Markdown files, relative to contentDir, forward slashes
	Assets []Asset
}

Sources lists the files found in contentDir.

func Discover

func Discover(dir string) (Sources, error)

Discover walks dir for Markdown files and other assets, skipping dotfiles and dot-directories. A missing dir yields no sources.

Jump to

Keyboard shortcuts

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