parser

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageRef added in v1.7.0

type ImageRef struct {
	// Ref is the raw path as it appeared in the source.
	Ref string
	// Source is the FilePath of the post or page that referenced the
	// image, so callers can produce a helpful warning if a transform
	// fails.
	Source string
	// Kind is "frontmatter" or "body" and helps with diagnostics.
	Kind string
}

ImageRef is one image reference extracted from a post or page. It is used by the v1.7 image-optimization pipeline to discover which source images need to be transformed into responsive variants.

The ref string is the path as written in the source — a relative URL (no scheme, no host). Callers are responsible for resolving it to an absolute on-disk path. The Source field records where the reference came from so callers can produce useful log lines.

func ExtractPageImageRefs added in v1.7.0

func ExtractPageImageRefs(p *Page) []ImageRef

ExtractPageImageRefs is the page analogue of ExtractPostImageRefs.

func ExtractPostImageRefs added in v1.7.0

func ExtractPostImageRefs(p *Post) []ImageRef

ExtractPostImageRefs returns the deduplicated list of image references in a post (front matter + body). The body scan looks at the raw Markdown source, not the rendered HTML, so it picks up references that goldmark may have re-written (e.g. escaped characters in URLs).

type Page added in v1.1.0

type Page struct {
	Title       string                 `yaml:"title"`
	Description string                 `yaml:"description"`
	Layout      string                 `yaml:"layout"`
	Slug        string                 `yaml:"slug"`
	Permalink   string                 `yaml:"permalink"`
	FilePath    string                 `yaml:"-"`
	Content     string                 `yaml:"-"`
	ContentHTML string                 `yaml:"-"`
	URL         string                 `yaml:"-"`
	Params      map[string]interface{} `yaml:"-"`
}

Page represents a standalone markdown page.

func ParsePage added in v1.1.0

func ParsePage(path string, baseDir string) (*Page, error)

ParsePage parses a standalone markdown page.

func ParsePageWithOptions added in v1.1.0

func ParsePageWithOptions(path string, baseDir string, opts RenderOptions) (*Page, error)

ParsePageWithOptions parses a standalone markdown page using render options.

func ParsePages added in v1.1.0

func ParsePages(dir string) ([]*Page, error)

ParsePages parses standalone markdown pages recursively from a directory.

func ParsePagesWithOptions added in v1.1.0

func ParsePagesWithOptions(dir string, opts RenderOptions) ([]*Page, error)

ParsePagesWithOptions parses standalone markdown pages recursively using render options. Parsing is parallelized with an automatically chosen worker count (min(NumCPU, 4)); results are returned in filepath.WalkDir's lexical order, so output is byte-for-byte identical to a serial parse.

func ParsePagesWithOptionsConcurrent added in v1.6.0

func ParsePagesWithOptionsConcurrent(dir string, opts RenderOptions, concurrency int) ([]*Page, error)

ParsePagesWithOptionsConcurrent parses standalone markdown pages recursively using render options and the requested worker count. A concurrency of 0 (or negative) means auto: min(NumCPU, 4). A value of 1 forces sequential parsing. Results are returned in filepath.WalkDir's lexical order.

type Post

type Post struct {
	// Front matter fields
	Title       string    `yaml:"title"`
	Date        time.Time `yaml:"date"`
	LastMod     time.Time `yaml:"lastmod"`
	Draft       bool      `yaml:"draft"`
	Published   *bool     `yaml:"published"`
	Description string    `yaml:"description"`
	Tags        []string  `yaml:"tags"`
	Categories  []string  `yaml:"categories"`
	Keywords    []string  `yaml:"keywords"`
	Slug        string    `yaml:"slug"`
	Aliases     []string  `yaml:"aliases"`
	Weight      int       `yaml:"weight"`
	Layout      string    `yaml:"layout"`

	// Internal fields
	FilePath    string                 `yaml:"-"`
	Content     string                 `yaml:"-"`
	ContentHTML string                 `yaml:"-"`
	WordCount   int                    `yaml:"-"`
	ReadingTime int                    `yaml:"-"`
	Summary     string                 `yaml:"-"`
	SummaryHTML string                 `yaml:"-"`
	URL         string                 `yaml:"-"`
	Section     string                 `yaml:"-"`
	Params      map[string]interface{} `yaml:"-"`
}

Post represents a blog post

func ParsePost

func ParsePost(path string) (*Post, error)

ParsePost parses a single markdown post file

func ParsePostWithOptions added in v1.1.0

func ParsePostWithOptions(path string, opts RenderOptions) (*Post, error)

ParsePostWithOptions parses a single markdown post file using render options.

func ParsePosts

func ParsePosts(dir string) ([]*Post, error)

ParsePosts parses all markdown posts from a directory

func ParsePostsWithOptions added in v1.1.0

func ParsePostsWithOptions(dir string, opts RenderOptions) ([]*Post, error)

ParsePostsWithOptions parses all markdown posts from a directory using render options. Parsing is parallelized with an automatically chosen worker count (min(NumCPU, 4)); results are returned in filepath.WalkDir's lexical order, so output is byte-for-byte identical to a serial parse.

func ParsePostsWithOptionsConcurrent added in v1.6.0

func ParsePostsWithOptionsConcurrent(dir string, opts RenderOptions, concurrency int) ([]*Post, error)

ParsePostsWithOptionsConcurrent parses all markdown posts from a directory using render options and the requested worker count. A concurrency of 0 (or negative) means auto: min(NumCPU, 4). A value of 1 forces sequential parsing. Results are returned in filepath.WalkDir's lexical order.

type RenderOptions added in v1.1.0

type RenderOptions struct {
	AllowUnsafeHTML bool

	// Shortcodes, when non-nil, expands Hugo-style shortcodes in the Markdown
	// source. It is excluded from JSON marshaling so it does not perturb the
	// incremental build env hash; shortcode template changes are tracked via
	// the templates/ and theme directory hashes instead.
	Shortcodes *shortcode.Registry `json:"-"`
}

RenderOptions controls Markdown rendering behavior.

func DefaultRenderOptions added in v1.1.0

func DefaultRenderOptions() RenderOptions

DefaultRenderOptions returns parser settings that avoid rendering raw HTML unless the site configuration explicitly opts in.

Jump to

Keyboard shortcuts

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