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
- Variables
- func ContentPathsForSidecar(sidecarPath string) []string
- func FormatNumber(f float64) string
- func IsContentFile(p string) bool
- func IsDataFile(p string) bool
- func NodeToValue(n *yaml.Node) (any, error)
- func ParseYAMLMap(raw []byte) (map[string]any, error)
- func SidecarPath(contentPath string) string
- func SplitFrontmatter(raw string) (frontmatter, body string, has bool)
- type Document
- type ItemMeta
- type Sidecar
Constants ¶
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 ¶
var Extensions = []string{".md", ".mdx", ".markdown", ".yml", ".yaml", ".json"}
Extensions of files the CMS treats as content.
Functions ¶
func ContentPathsForSidecar ¶
ContentPathsForSidecar returns the content files a sidecar could belong to, one per content extension, since the sidecar drops the extension.
func FormatNumber ¶
FormatNumber renders a float the way the editor prints it: integers without a fraction.
func IsContentFile ¶
IsContentFile reports whether the path has a content extension.
func IsDataFile ¶
IsDataFile reports whether the path is a whole-file YAML data document rather than Markdown with a frontmatter fence.
func NodeToValue ¶
NodeToValue converts a YAML node tree to plain values with the scalar rules of ParseYAMLMap. Mapping keys are rendered as strings.
func ParseYAMLMap ¶
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 ¶
SidecarPath returns the sidecar path of a content file.
func SplitFrontmatter ¶
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.
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.