doc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package doc parses YAML frontmatter and represents the indexable document model that all downstream layers consume.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Split

func Split(content []byte) (frontmatter map[string]any, body []byte, err error)

Split extracts the YAML frontmatter block from a file body. The frontmatter must start at the very first byte with `---\n` and end with a line that is exactly `---`. When no frontmatter is detected (or the closing delimiter is missing), the returned frontmatter is nil and body equals the input content. A YAML parse error is returned as-is so callers can decide whether to fail the index or fall back to a raw body.

Types

type Doc

type Doc struct {
	Path        string         // repo-relative, forward slashes
	Title       string         // frontmatter.title -> first H1 -> filename
	Tags        []string       // frontmatter.tags, normalized (lowercase, trimmed)
	Body        string         // file body sans frontmatter (or full file if no frontmatter)
	Frontmatter map[string]any // raw frontmatter (nil when absent)
	ModTime     time.Time      // filled by sync
	Size        int64          // filled by sync
	Digest      string         // git-blob SHA, filled by sync
}

Doc is the indexable representation of a single file.

func FromBytes

func FromBytes(filePath string, content []byte) (*Doc, error)

FromBytes builds a Doc from file contents. path is the repo-relative forward-slash path used both as the doc ID and as the fallback for title derivation.

func (*Doc) Flatten

func (d *Doc) Flatten() map[string]any

Flatten returns the field map used to populate a Bleve document. Frontmatter is merged in with one level of nesting flattened to dotted keys (e.g. `service.name`). Reserved Doc fields always win over raw frontmatter entries with the same key.

Jump to

Keyboard shortcuts

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