Documentation
¶
Index ¶
- func LoadDataFiles(dataDir string) (map[string]interface{}, error)
- func ParseFrontmatter(data []byte) (frontmatter map[string]interface{}, body string, err error)
- type Page
- func LoadDir(contentDir string) ([]*Page, error)
- func LoadDirWithCache(contentDir string, cache *ParseCache, observe func(path string, data []byte)) ([]*Page, error)
- func LoadDirWithObserver(contentDir string, observe func(path string, data []byte)) ([]*Page, error)
- func LoadPageFromFrontmatterData(data []byte, relPath string) (*Page, error)
- type ParseCache
- type ParseCacheStats
- type Site
- type Taxonomy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadDataFiles ¶
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"]
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"
Language string // language code (e.g. "zh-cn", "en"); empty = default
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
// Version number, atomically incremented on each page load.
// Used by ContextCache to detect page changes and invalidate cached
// template context.
Version uint64
// 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 ¶
LoadDir recursively loads all .md files from the content directory.
Files are recognized by suffix per Hugo's convention:
- `<name>.md` → default language (page.Language = "")
- `<name>.<lang>.md` → sidecar for that language (e.g. foo.en.md → "en")
- `<name>.<region>.md` → sidecar for region-tagged language (e.g. foo.zh-cn.md → "zh-cn")
The default-language code (e.g. "zh-cn") is NOT auto-applied to `<name>.md` files; callers comparing languages should treat empty Language as the default. Use Page.IsDefaultLanguage(defaultCode) for that check.
func LoadDirWithCache ¶ added in v0.11.20
func LoadDirWithCache(contentDir string, cache *ParseCache, observe func(path string, data []byte)) ([]*Page, error)
LoadDirWithCache loads all current Markdown files and optionally reuses parsed inputs. Every file is read and observed before any cache lookup, so edits with unchanged size/mtime and observer-dependent checks see the current bytes. Returned pages have independent mutable state and newly assigned versions. As with LoadDirWithObserver, observe must not modify the supplied bytes.
func LoadDirWithObserver ¶ added in v0.11.20
func LoadDirWithObserver(contentDir string, observe func(path string, data []byte)) ([]*Page, error)
LoadDirWithObserver loads pages like LoadDir and calls observe, when non-nil, with each markdown file's path and raw bytes after reading and before parsing. The callback must not modify data; it should copy any bytes it retains.
func LoadPageFromFrontmatterData ¶ added in v0.7.0
LoadPageFromFrontmatterData creates a Page from raw file data. This is the exported version used by JITRenderFast and other callers that need to construct a Page from already-read file bytes without going through the full LoadDir pipeline.
func (*Page) IsDefaultLanguage ¶ added in v0.3.0
IsDefaultLanguage returns true when the page belongs to the default language. A page belongs to the default language when its Language field is empty (no `.<lang>.md` suffix) OR explicitly matches defaultCode.
Callers that need to filter pages by language should prefer this helper over direct string comparison: it handles the empty-string-as-default convention uniformly.
type ParseCache ¶ added in v0.11.20
type ParseCache struct {
// contains filtered or unexported fields
}
ParseCache reuses immutable parsed Markdown inputs across directory loads. It is safe to share across builds and sites. The zero value disables storage. Capacity bounds owned string data and a conservative bookkeeping allowance, not the Go allocator's exact heap size. Do not copy after first use.
func NewParseCache ¶ added in v0.11.20
func NewParseCache(maxBytes int64) *ParseCache
NewParseCache creates an LRU with a bounded byte budget for parsed inputs. Nonpositive capacities disable storage. All files are still read each load; only identical path-and-content pairs reuse their parsed fields.
func (*ParseCache) Stats ¶ added in v0.11.20
func (c *ParseCache) Stats() ParseCacheStats
Stats returns a consistent snapshot of the cache counters and capacity.
type ParseCacheStats ¶ added in v0.11.20
ParseCacheStats describes cumulative lookups and retained input versions.
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.