content

package
v0.4.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindTemplateTagBlock = ast.NewNodeKind("TemplateTagBlock")
View Source
var KindTemplateTagInline = ast.NewNodeKind("TemplateTagInline")

Functions

func CreateGoldmark

func CreateGoldmark(opts MarkdownOptions, extraParserOpts ...parser.Option) goldmark.Markdown

CreateGoldmark builds a configured goldmark instance from options. When TemplateTags is true, template tags are preserved verbatim in the output. When false, they are escaped with zero-width spaces so the template engine won't recognize them.

func ParseFrontMatter

func ParseFrontMatter(raw []byte) (map[string]interface{}, []byte, error)

ParseFrontMatter extracts front matter and body from raw content. Detects YAML (---), TOML (+++), or JSON ({) delimiters.

func RenderText

func RenderText(source []byte) ([]byte, error)

RenderText wraps plain text content in <pre> tags for .txt files.

func SplitAtDelimiter

func SplitAtDelimiter(raw []byte, delim string) (before, after []byte, found bool)

SplitAtDelimiter splits raw bytes at a delimiter line, returning content before and after.

Types

type HookRenderer

type HookRenderer func(source string, ctx map[string]interface{}) (string, error)

HookRenderer renders a hook template with the given context variables. source is the template source and ctx contains the template variables (e.g. {"markup": {...}}).

type MarkdownOptions

type MarkdownOptions struct {
	Unsafe         bool
	Typographer    bool
	TemplateTags   bool
	AutoHeadingID  bool
	CustomElements bool
	Hooks          map[string]string
	HookRenderer   HookRenderer
}

MarkdownOptions controls goldmark rendering behavior.

type Page

type Page struct {
	SourcePath   string
	RelPath      string
	Content      []byte
	FrontMatter  map[string]interface{}
	Body         []byte
	RenderedBody []byte
	OutputPath   string
	URL          string
	Date         time.Time
	Draft        bool
	PublishDate  *time.Time
	ExpiryDate   *time.Time
	Summary      string
	Layout       string
	Outputs      []string
	FormatBodies map[string][]byte // alternate format rendered bodies (e.g., "json" → rendered JSON)
	Aliases      []string
	Permalink    string
	Slug         string
	Section      string
	Kind         string // "page", "taxonomy", "taxonomy_term", "home", "section"
	Collection   string
	Translations []*Page
	Pagination   *PaginationFrontMatter
	Bundle       bool
	BundleAssets []string
	TOC          []TOCEntry
	// contains filtered or unexported fields
}

Page represents a single content file with its metadata and rendered output.

func BuildPage

func BuildPage(relPath string, raw []byte) (*Page, error)

BuildPage parses raw content bytes and returns a fully populated Page.

func Discover

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

Discover walks the content directory and returns all content pages.

func DiscoverWithFormats

func DiscoverWithFormats(contentDir string, formats []string) ([]*Page, error)

DiscoverWithFormats walks the content directory and returns only pages whose file extension matches one of the allowed formats.

func DiscoverWithPassthrough

func DiscoverWithPassthrough(contentDir string, formats []string) ([]*Page, []string, error)

DiscoverWithPassthrough walks the content directory and returns content pages (files matching formats) and passthrough file paths (everything else). Excludes _data.yaml, _data.yml, and dot-prefixed files from passthrough.

func FilterByLifecycle

func FilterByLifecycle(pages []*Page, now time.Time, includeDrafts bool) []*Page

FilterByLifecycle removes draft, future, and expired pages based on the current time. In dev mode (includeDrafts=true), drafts are kept and draft pages bypass date constraints. publishDate and expiryDate filtering applies in both build and serve modes.

func (*Page) HTML

func (p *Page) HTML() string

HTML returns the string conversion of RenderedBody, caching the result so subsequent calls avoid redundant []byte→string allocations.

func (*Page) SetRenderedBody

func (p *Page) SetRenderedBody(b []byte)

SetRenderedBody updates RenderedBody and clears the cached HTML string.

func (*Page) ToTemplateMap

func (p *Page) ToTemplateMap() map[string]interface{}

ToTemplateMap converts a Page to a map with lowercase keys for reliable Liquid template access. Struct fields (URL, Date, etc.) are merged on top of FrontMatter so templates can use {{ page.title }}, {{ page.url }}, etc.

type PaginationFrontMatter

type PaginationFrontMatter struct {
	Data    string `yaml:"data" json:"data"`
	PerPage int    `yaml:"perPage" json:"perPage"`
	As      string `yaml:"as" json:"as"`
}

PaginationFrontMatter holds pagination settings from front matter.

type TOCEntry

type TOCEntry struct {
	ID       string     `json:"id"`
	Text     string     `json:"text"`
	Level    int        `json:"level"`
	Children []TOCEntry `json:"children,omitempty"`
}

TOCEntry represents a heading in the table of contents.

func RenderMarkdown

func RenderMarkdown(source []byte, md goldmark.Markdown) ([]byte, []TOCEntry, error)

RenderMarkdown converts Markdown source to HTML and extracts a table of contents using a pre-created goldmark instance. Use this when rendering multiple pages with the same options to avoid re-creating the instance per page. The goldmark instance must have AutoHeadingID enabled for TOC IDs.

type TemplateTagBlock

type TemplateTagBlock struct {
	ast.BaseBlock
	TagText []byte
}

func (*TemplateTagBlock) Dump

func (n *TemplateTagBlock) Dump(source []byte, level int)

func (*TemplateTagBlock) IsRaw

func (n *TemplateTagBlock) IsRaw() bool

func (*TemplateTagBlock) Kind

func (n *TemplateTagBlock) Kind() ast.NodeKind

type TemplateTagInline

type TemplateTagInline struct {
	ast.BaseInline
	TagText []byte
}

func (*TemplateTagInline) Dump

func (n *TemplateTagInline) Dump(source []byte, level int)

func (*TemplateTagInline) IsRaw

func (n *TemplateTagInline) IsRaw() bool

func (*TemplateTagInline) Kind

func (n *TemplateTagInline) Kind() ast.NodeKind

Jump to

Keyboard shortcuts

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