frontmatter

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package frontmatter provides Hugo-compatible YAML frontmatter parsing and generation.

Index

Constants

View Source
const (
	SourceChatGPT    = "chatgpt"
	SourceClaude     = "claude"
	SourceClaudeCode = "claude-code"
	SourceGemini     = "gemini"
	SourcePerplexity = "perplexity"
	SourceCodex      = "codex"
)

Source platform identifiers

Variables

View Source
var (
	// ErrInvalidFrontmatter indicates malformed frontmatter
	ErrInvalidFrontmatter = errors.New("invalid frontmatter format")
)

Functions

func ExtractDescription

func ExtractDescription(content []byte, maxLen int) string

ExtractDescription extracts a description from content (first non-empty line or first N chars).

func GenerateConversationID

func GenerateConversationID() string

GenerateConversationID creates a unique conversation ID.

func GeneratePath

func GeneratePath(folder, source, title string, date time.Time) string

GeneratePath creates a file path for a conversation. Format: {folder}/{source}/{date}_{slug}.md

func GenerateSlug

func GenerateSlug(title string) string

GenerateSlug creates a URL-friendly slug from a title.

func ValidSource

func ValidSource(source string) bool

ValidSource checks if a source is valid.

Types

type Frontmatter

type Frontmatter struct {
	// Hugo standard fields
	Title       string    `yaml:"title"`
	Date        time.Time `yaml:"date"`
	LastMod     time.Time `yaml:"lastmod,omitempty"`
	Draft       bool      `yaml:"draft,omitempty"`
	Tags        []string  `yaml:"tags,omitempty"`
	Categories  []string  `yaml:"categories,omitempty"`
	Author      string    `yaml:"author,omitempty"`
	Description string    `yaml:"description,omitempty"`
	Slug        string    `yaml:"slug,omitempty"`
	Weight      int       `yaml:"weight,omitempty"`
	Aliases     []string  `yaml:"aliases,omitempty"`

	// ChatHub extension fields
	Source         string   `yaml:"source"`
	ConversationID string   `yaml:"conversation_id,omitempty"`
	Participants   []string `yaml:"participants,omitempty"`
	MessageCount   int      `yaml:"message_count,omitempty"`
	Model          string   `yaml:"model,omitempty"`
	Tokens         int      `yaml:"tokens,omitempty"`
}

Frontmatter represents Hugo-compatible YAML frontmatter with ChatHub extensions.

func New

func New(title, source string) *Frontmatter

New creates a new Frontmatter with default values.

func Parse

func Parse(content []byte) (*Frontmatter, []byte, error)

Parse extracts frontmatter from Markdown content. Returns the parsed frontmatter, the remaining content, and any error.

func (*Frontmatter) Render

func (f *Frontmatter) Render() ([]byte, error)

Render generates YAML frontmatter bytes.

func (*Frontmatter) RenderWithContent

func (f *Frontmatter) RenderWithContent(content []byte) ([]byte, error)

RenderWithContent generates complete Markdown with frontmatter and content.

Jump to

Keyboard shortcuts

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