content

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package content loads Markdown collections with YAML/TOML/JSON frontmatter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, dst any) (body []byte, err error)

Decode parses frontmatter from raw file bytes into dst and returns the Markdown body.

func RenderMarkdown

func RenderMarkdown(src []byte) (string, error)

RenderMarkdown converts Markdown to HTML using the package default engine.

func RenderMarkdownUnsafe

func RenderMarkdownUnsafe(src []byte) (string, error)

RenderMarkdownUnsafe renders raw HTML for trusted-author content only.

Types

type Document

type Document[T any] struct {
	Collection string
	Slug       string
	Path       string // absolute path on disk
	Meta       T
	Body       string // HTML
	Raw        string // Markdown body without frontmatter
}

Document is a Markdown file with typed frontmatter and rendered HTML body.

func Get

func Get[T any](s *Store, collection, slug string) (*Document[T], error)

Get returns a typed document by collection and slug.

func List

func List[T any](s *Store, collection string) ([]Document[T], error)

List returns typed documents for a collection, sorted by slug.

type Entry

type Entry = Document[map[string]any]

Entry is an untyped document (frontmatter as map).

type Options

type Options struct {
	UnsafeHTML bool
}

Options controls Markdown rendering. Raw HTML is escaped unless UnsafeHTML is explicitly set for trusted-author content.

type Store

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

Store holds loaded collections from a content root directory.

func Load

func Load(dir string) (*Store, error)

Load scans dir for content/<collection>/**/*.md and indexes them. dir itself is the content root (e.g. "./content").

func LoadWithOptions

func LoadWithOptions(dir string, opts Options) (*Store, error)

LoadWithOptions is Load with explicit Markdown rendering options.

func (*Store) Collections

func (s *Store) Collections() []string

Collections returns sorted collection names.

func (*Store) Get

func (s *Store) Get(collection, slug string) (*Entry, error)

Get returns one document by collection and slug with map frontmatter.

func (*Store) List

func (s *Store) List(collection string) ([]Entry, error)

List returns all documents in a collection with map frontmatter, sorted by slug.

func (*Store) Root

func (s *Store) Root() string

Root returns the absolute content root directory.

Jump to

Keyboard shortcuts

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