content

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SyntaxHighlight bool

SyntaxHighlight controls whether Chroma server-side syntax highlighting is enabled.

Functions

func AllTags

func AllTags(pages []*Page) []string

AllTags returns a deduplicated list of all tags across all pages.

func ApplySlugURL added in v0.2.0

func ApplySlugURL(base string, page *Page) string

ApplySlugURL applies slug and url front matter overrides to a base permalink. page.Kind must be set before calling.

func DepthFromPath

func DepthFromPath(contentDir, filePath string) int

DepthFromPath calculates depth: home=0, top-level=1, nested=2, etc.

func HashFile

func HashFile(path string) (string, error)

HashFile computes SHA-256 of a file and returns hex string.

func KindFromPath

func KindFromPath(contentDir, filePath string) string

KindFromPath determines the page kind from its file path.

func OutputPathFromPermalink(outputDir, permalink string) string

OutputPathFromPermalink converts a permalink to an output file path.

func PermalinkFromPath

func PermalinkFromPath(contentDir, filePath, defaultLang string) (string, string)

PermalinkFromPath derives the base permalink from a file path.

func SectionFromPath

func SectionFromPath(contentDir, filePath string) string

SectionFromPath extracts the top-level section name.

func TagCounts

func TagCounts(pages []*Page) map[string]int

TagCounts returns map[tag]count.

func WriteChromaCSS added in v0.2.0

func WriteChromaCSS(path string) (string, error)

WriteChromaCSS writes a combined light+dark syntax-highlight stylesheet.

Types

type LoadOptions

type LoadOptions struct {
	ContentDir  string
	DefaultLang string
	OutputDir   string
}

LoadOptions configures the content loader.

type Page

type Page struct {
	FilePath  string
	FileHash  string
	FileSize  int64
	FileMtime int64

	// URL fields
	RelPermalink string
	Permalink    string // full URL with base URL (set by build)
	OutputPath   string
	Slug         string   // front matter slug: overrides last URL segment
	URL          string   // front matter url: overrides entire permalink
	Aliases      []string // redirect aliases

	// Core metadata
	Title       string
	LinkTitle   string
	Description string
	Summary     string
	Date        time.Time
	PublishDate time.Time
	ExpiryDate  time.Time
	Lastmod     time.Time
	Draft       bool
	Weight      int
	Type        string // content type: front matter or root section name
	Layout      string // explicit template name override

	// Taxonomy fields
	Tags       []string
	Categories []string
	Keywords   []string
	Taxonomies map[string][]string // plural name -> terms

	// Visibility
	NoIndex       bool
	ExcludeSearch bool

	// Arbitrary front matter params
	Params map[string]any

	// Cascade: front matter values to inherit down to descendant pages.
	// Only set on section/home pages. Applied in BuildTree.
	Cascade map[string]any

	// Page classification
	Kind    string // "page"|"section"|"home"|"term"|"taxonomy"
	Lang    string
	Section string // root section name (first dir under content/)
	Depth   int

	// Tree structure
	Parent    *Page
	Children  []*Page
	Ancestors []*Page

	// Siblings (populated by build after tree is built)
	NextPage *Page
	PrevPage *Page

	// Rendered content
	ContentHTML  string
	ContentPlain string
	ReadingTime  int
	WordCount    int
}

Page represents a single content page or section.

func BuildTree

func BuildTree(pages []*Page) []*Page

BuildTree sets Parent, Children, and Ancestors for all pages. It builds the hierarchy based on permalinks.

It also synthesizes in-memory section pages for any directory that holds content but has no _index.md, mirroring Hugo, which creates a section for every such directory. Without this, a page nested under a dir with no _index.md would have no parent and drop out of .RegularPagesRecursive even though it still renders as a standalone page. The synthesized sections are returned so the caller can finish them (output path, permalink) and add them to the render set; they carry an empty FilePath, which the build pipeline treats as always-render, never-cache.

func FilterBySection

func FilterBySection(pages []*Page, section string) []*Page

FilterBySection returns pages belonging to a specific section (not including section index itself).

func FilterByTag

func FilterByTag(pages []*Page, tag string) []*Page

FilterByTag returns all pages that have the given tag.

func FindByPermalink(pages []*Page, permalink string) *Page

FindByPermalink returns a page by its permalink.

func FindHome

func FindHome(pages []*Page) *Page

FindHome returns the home page (Kind=="home") or nil.

func LoadAll

func LoadAll(opts LoadOptions) ([]*Page, error)

LoadAll walks contentDir, parses all markdown files, and builds the page tree. It returns all pages including the home page and section indexes.

func ParseAndRender

func ParseAndRender(filePath string) (*Page, error)

ParseAndRender reads a markdown file, parses front matter, and renders HTML.

func RegularPages

func RegularPages(pages []*Page) []*Page

RegularPages returns pages with Kind=="page".

func SectionPages

func SectionPages(pages []*Page) []*Page

SectionPages returns section index pages (Kind=="section").

func (*Page) Content added in v0.2.0

func (p *Page) Content() template.HTML

Content returns the HTML content for direct template access via .Page.Content.

func (*Page) ContentBaseName added in v0.2.0

func (p *Page) ContentBaseName() string

ContentBaseName returns the base name of the content file (without extension).

func (*Page) FuzzyWordCount added in v0.2.0

func (p *Page) FuzzyWordCount() int

FuzzyWordCount returns WordCount rounded to the nearest 100.

func (*Page) IsHome added in v0.2.0

func (p *Page) IsHome() bool

IsHome reports whether this is the site home page.

func (*Page) IsNode added in v0.2.0

func (p *Page) IsNode() bool

IsNode reports whether this is a list page (home, section, taxonomy, term).

func (*Page) IsPage added in v0.2.0

func (p *Page) IsPage() bool

IsPage reports whether this is a regular content page.

func (*Page) IsSection added in v0.2.0

func (p *Page) IsSection() bool

IsSection reports whether this is a section index page.

func (*Page) Pages added in v0.2.0

func (p *Page) Pages() []*Page

Pages returns direct children (for list templates).

func (*Page) Paginator added in v0.2.0

func (p *Page) Paginator() any

Paginator returns nil (stub for Hugo .Paginator on content.Page — not available outside TemplateData context).

func (*Page) Path added in v0.2.0

func (p *Page) Path() string

Path returns the logical path of the page (its RelPermalink).

func (*Page) Plain added in v0.2.0

func (p *Page) Plain() string

Plain returns plain-text content for templates.

func (*Page) RegularPages added in v0.2.0

func (p *Page) RegularPages() []*Page

RegularPages returns only Kind=="page" children.

func (*Page) Resources added in v0.2.0

func (p *Page) Resources() *PageResourcesStub

Resources returns a stub resources object for this page.

func (*Page) Sections added in v0.2.0

func (p *Page) Sections() []*Page

Sections returns only Kind=="section" children.

func (*Page) Store added in v0.2.0

func (p *Page) Store() *PageScratch

Store returns a per-page scratch pad (Hugo 0.117+).

type PageResourcesStub added in v0.2.0

type PageResourcesStub struct{}

PageResourcesStub is a minimal stub for page-level resources (image processing etc). The actual resource implementation lives in pkg/render to avoid circular imports, but content.Page needs to expose Resources() for direct template access via .Page.Resources.

func (*PageResourcesStub) ByType added in v0.2.0

func (r *PageResourcesStub) ByType(t string) []any

func (*PageResourcesStub) Get added in v0.2.0

func (r *PageResourcesStub) Get(name string) any

func (*PageResourcesStub) GetMatch added in v0.2.0

func (r *PageResourcesStub) GetMatch(pattern string) any

func (*PageResourcesStub) Match added in v0.2.0

func (r *PageResourcesStub) Match(pattern string) []any

type PageScratch added in v0.2.0

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

PageScratch is a lightweight scratch pad used by content.Page.Store.

func (*PageScratch) Delete added in v0.2.0

func (s *PageScratch) Delete(key string) string

func (*PageScratch) Get added in v0.2.0

func (s *PageScratch) Get(key string) any

func (*PageScratch) Set added in v0.2.0

func (s *PageScratch) Set(key string, val any) string

func (*PageScratch) SetInMap added in v0.2.0

func (s *PageScratch) SetInMap(key, mapKey string, val any) string

Jump to

Keyboard shortcuts

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