template

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package template provides template processing and ID generation for notes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID(path, noteType string) string

GenerateID creates a deterministic note ID from the note file path and type. The ID is formed as "<type>-<slug>" where slug is the lowercase, hyphenated base filename (without the .md extension).

func SubstituteVars

func SubstituteVars(content string, vars map[string]string) (string, []string)

SubstituteVars replaces <%=name%> placeholders in content using vars. Unknown variable names are left as-is and reported in warnings.

Types

type ProcessConfig

type ProcessConfig struct {
	VaultPath      string            // absolute path to vault root (for metadata)
	Path           string            // vault-relative path of the new note
	Type           string            // note type (e.g. "project", "decision")
	Fields         map[string]string // field overrides (includes optional "title", "id", …)
	Body           string            // explicit body override; empty means use template body
	TemplatePath   string            // absolute path to the template file
	RequiredFields []string          // type-specific required fields (for minimal fallback)
}

ProcessConfig holds all inputs needed to process a note template.

type ProcessResult

type ProcessResult struct {
	Content          []byte                 // serialized YAML-frontmatter + body
	ID               string                 // final note ID
	Path             string                 // echoes ProcessConfig.Path
	Warnings         []string               // non-fatal issues (e.g. unknown template vars, missing template)
	FinalFrontmatter map[string]interface{} // the final frontmatter map after all substitutions and overrides
}

ProcessResult is the output of a successful Process call.

func Process

func Process(cfg ProcessConfig) (*ProcessResult, error)

Process executes the full note-creation pipeline:

  1. Load template from disk (fallback to minimal note if missing)
  2. Build variable map and substitute placeholders
  3. Parse frontmatter
  4. Apply field overrides from cfg.Fields
  5. Ensure core fields (id, type) are present and a `created` stamp is set — see schema/registry.go for the field taxonomy.
  6. Override body if cfg.Body is set
  7. Serialize and return

Jump to

Keyboard shortcuts

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