Documentation
¶
Overview ¶
Package content discovers source files and models pages: front matter, URL mapping and titles.
Index ¶
- func AssetPath(rel string) string
- func FirstH1(doc ast.Node, source []byte) string
- func Humanize(s string) string
- func IsSectionIndex(rel string) bool
- func NumericPrefix(seg string) int
- func OutputPath(url string) string
- func PlainText(n ast.Node, source []byte) string
- func SplitFrontMatter(src []byte) (fm, body []byte, bodyLine int, err error)
- func StripNumericPrefix(seg string) string
- func TitleFromPath(rel string) string
- func URLFor(rel, slug string) string
- func WalkFiles(root string, fn func(path, rel string)) error
- type Asset
- type FrontMatter
- type Page
- type Sources
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssetPath ¶
AssetPath maps a non-Markdown file in contentDir to its output path, stripping numeric prefixes from its directories like URLFor does.
func IsSectionIndex ¶
IsSectionIndex reports whether a content file is a section index page (_index.md or index.md).
func NumericPrefix ¶
NumericPrefix returns the ordering prefix of a path segment ("02-setup" -> 2), or -1 if StripNumericPrefix would not remove one.
func OutputPath ¶
OutputPath maps a page URL to the file it is written to, relative to outputDir: "/docs/setup/" -> "docs/setup/index.html".
func SplitFrontMatter ¶
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 ¶
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 ¶
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 ¶
URLFor maps a Markdown file path, relative to contentDir and using forward slashes, to its clean URL (spec §5.2):
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.
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 (spec §5.1).
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
}
Page is one Markdown source file and everything derived from it. The embedded plugin.Page is the part plugins see.