content

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package content reads content files the way the CMS does: Markdown with a YAML frontmatter fence, or a whole-file YAML data document, into plain Go values (maps, slices, strings, numbers, booleans) that match what the editor sees after its YAML to JSON round trip.

Index

Constants

View Source
const SidecarDir = ".norcube/cms/meta"

SidecarDir is where the CMS keeps block identities, mirroring the content tree: `src/content/pages/about.md` has its sidecar at `.norcube/cms/meta/src/content/pages/about.yml`.

Variables

View Source
var Extensions = []string{".md", ".mdx", ".markdown", ".yml", ".yaml", ".json"}

Extensions of files the CMS treats as content.

Functions

func ContentPathsForSidecar

func ContentPathsForSidecar(sidecarPath string) []string

ContentPathsForSidecar returns the content files a sidecar could belong to, one per content extension, since the sidecar drops the extension.

func FormatNumber

func FormatNumber(f float64) string

FormatNumber renders a float the way the editor prints it: integers without a fraction.

func IsContentFile

func IsContentFile(p string) bool

IsContentFile reports whether the path has a content extension.

func IsDataFile

func IsDataFile(p string) bool

IsDataFile reports whether the path is a whole-file YAML data document rather than Markdown with a frontmatter fence.

func NodeToValue

func NodeToValue(n *yaml.Node) (any, error)

NodeToValue converts a YAML node tree to plain values with the scalar rules of ParseYAMLMap. Mapping keys are rendered as strings.

func ParseYAMLMap

func ParseYAMLMap(raw []byte) (map[string]any, error)

ParseYAMLMap parses a YAML document into a string-keyed map of plain values. Scalars keep the type their tag gives them: integers and floats become float64 (as JSON would), booleans stay booleans, null is nil, and everything else, timestamps included, stays the text as written. An empty document is an empty map; a document whose root is not a mapping is an error.

func SidecarPath

func SidecarPath(contentPath string) string

SidecarPath returns the sidecar path of a content file.

func SplitFrontmatter

func SplitFrontmatter(raw string) (frontmatter, body string, has bool)

SplitFrontmatter pulls the YAML head out of a Markdown file. Leading whitespace before the opening fence is accepted. The third result is false, and the whole text is the body, when there is no fence.

Types

type Document

type Document struct {
	Path string
	// Frontmatter is the YAML head (or the whole data file) as plain values.
	Frontmatter map[string]any
	// Body is the Markdown after the fence; empty for data files.
	Body string
	// HasFrontmatter is false for a Markdown file without a fence.
	HasFrontmatter bool
	// IsData is true for a whole-file YAML document.
	IsData bool
}

Document is one parsed content file.

func Parse

func Parse(p string, raw []byte) (Document, error)

Parse reads one content file. A parse error in the YAML is returned; the caller decides whether that is a finding or fatal.

type ItemMeta

type ItemMeta struct {
	ID     string                `yaml:"id"`
	Hashes []string              `yaml:"hashes,omitempty"`
	Arrays map[string][]ItemMeta `yaml:"arrays,omitempty"`
}

ItemMeta is the identity of one array item.

type Sidecar

type Sidecar struct {
	SchemaVersion int                   `yaml:"schemaVersion"`
	Page          string                `yaml:"page,omitempty"`
	Arrays        map[string][]ItemMeta `yaml:"arrays,omitempty"`
}

Sidecar is one identity file.

func ParseSidecar

func ParseSidecar(raw []byte) (Sidecar, error)

ParseSidecar reads a sidecar file.

Jump to

Keyboard shortcuts

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