content

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDataFiles

func LoadDataFiles(dataDir string) (map[string]interface{}, error)

LoadDataFiles loads all data files from the data/ directory. Supports .yaml, .yml, .json. Returns a nested map matching the directory structure. e.g., data/books.yaml → map["books"]

func ParseFrontmatter

func ParseFrontmatter(data []byte) (frontmatter map[string]interface{}, body string, err error)

ParseFrontmatter splits a markdown file into frontmatter and body.

Types

type Page

type Page struct {
	// Frontmatter fields
	Title         string   `yaml:"title"`
	Date          string   `yaml:"date"`
	PublishDate   string   `yaml:"publishDate"`
	ExpiryDate    string   `yaml:"expiryDate"`
	Lastmod       string   `yaml:"lastmod"`
	Draft         bool     `yaml:"draft"`
	Hidden        bool     `yaml:"hidden"`
	Type          string   `yaml:"type"`
	Slug          string   `yaml:"slug"`
	Tags          []string `yaml:"tags"`
	Keywords      []string `yaml:"keywords"`
	Description   string   `yaml:"description"`
	Author        string   `yaml:"author"`
	Image         string   `yaml:"image"`
	FeaturedImage string   `yaml:"featured_image"`

	// Hugo build directives
	Build   config.BuildConfig       `yaml:"build"`
	Cascade config.CascadeConfig     `yaml:"cascade"`
	Sitemap config.SitemapPageConfig `yaml:"sitemap"`

	// Computed fields (populated during loading)
	FilePath          string
	RelPath           string // relative to content/ e.g. "posts/2020/08/2601.md"
	URL               string // e.g. "/posts/2020/08/2601/"
	Section           string // e.g. "posts", "books", "gallery"
	Kind              string // "page", "section", "home", "taxonomy", "term"
	Content           template.HTML
	Summary           template.HTML
	Plain             string
	WordCount         int
	ReadingTime       int
	DateParsed        time.Time
	PublishDateParsed time.Time
	ExpiryDateParsed  time.Time
	LastmodParsed     time.Time
	Weight            int

	// Raw markdown body (before rendering)
	RawContent string

	// Tree structure
	Parent                *Page
	Pages                 []*Page
	RegularPages          []*Page
	RegularPagesRecursive []*Page // all descendant regular pages, recursively
	Sections              []*Page // immediate child section pages
}

Page represents a single content page.

func LoadDir

func LoadDir(contentDir string) ([]*Page, error)

LoadDir recursively loads all .md files from the content directory.

func (*Page) IsHome

func (p *Page) IsHome() bool

IsHome returns true for the root index page.

func (*Page) IsPage

func (p *Page) IsPage() bool

IsPage returns true for regular content pages.

func (*Page) IsSection

func (p *Page) IsSection() bool

IsSection returns true for section index pages.

type Site

type Site struct {
	Title        string
	BaseURL      string
	Language     string
	Params       map[string]interface{}
	Menus        map[string][]config.MenuItem
	Pages        []*Page
	RegularPages []*Page
	Data         map[string]interface{}
	Taxonomies   map[string]Taxonomy
	Config       *config.Config

	// Section index pages
	Sections map[string]*Page

	// TaxonomyOriginalCase maps plural (e.g. "tags") → {urlized-key → originalcased-name}.
	// Used to recover display casing for term-page titles (e.g. FANFAN) while
	// keeping the urlized key (e.g. fanfan) for filesystem paths and URL paths.
	TaxonomyOriginalCase map[string]map[string]string
}

Site holds all site-wide data.

func BuildTree

func BuildTree(pages []*Page, cfg *config.Config, sourceDir string) (*Site, error)

BuildTree takes raw pages and assembles the content tree:

  • determines Kind (home, section, page)
  • computes URL from file path
  • determines Section
  • builds parent/child relationships
  • renders Markdown to HTML
  • filters drafts

type Taxonomy

type Taxonomy map[string][]*Page

Taxonomy maps a tag name to its pages.

Jump to

Keyboard shortcuts

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