templates

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package templates is the note-template system: the built-ins the app ships, custom templates parsed from `.zennotes/templates/*.md`, and the `{{variable}}` substitution applied when a note is created from one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeFile

func ComposeFile(in ComposeInput) string

ComposeFile builds a raw template `.md` from structured fields.

func RenderTitle

func RenderTitle(titleTemplate, title string, now time.Time) string

RenderTitle expands a title pattern; cursor tokens drop.

func SlugifyName

func SlugifyName(name string) string

SlugifyName turns a display name into a safe, lowercase filename stem.

Types

type ComposeInput

type ComposeInput struct {
	Name          string
	Description   string
	Category      string
	TitleTemplate string
	TargetFolder  vault.NoteFolder
	TargetSubpath string
	BuiltinID     string
	Body          string
}

ComposeInput describes a template file to write.

type Rendered

type Rendered struct {
	Body         string
	CursorOffset int
}

Rendered is a template body with its tokens expanded; CursorOffset is the rune offset of `{{cursor}}` in the body, or -1 when absent.

func Render

func Render(body, title string, now time.Time) Rendered

Render expands a template body.

type Template

type Template struct {
	// ID is `builtin.<name>` for a built-in, `custom:<slug>` for a custom one.
	ID          string
	Name        string
	Description string
	Category    string
	// Body is markdown with `{{title}}`, `{{date}}`, `{{cursor}}` tokens.
	Body string
	// TitleTemplate is an optional title pattern.
	TitleTemplate string
	// TargetFolder is the default destination, never trash.
	TargetFolder  vault.NoteFolder
	TargetSubpath string
	Builtin       bool
	SourcePath    string
	// BuiltinID marks a custom template that is an edited copy of a
	// built-in; it shadows the built-in everywhere.
	BuiltinID string
}

Template is a note template, built-in or custom.

func All

func All(custom []vault.CustomTemplateFile, hideBuiltins bool) []Template

All is Merge over the built-ins (unless hidden) and the vault's custom templates.

func Builtins

func Builtins() []Template

Builtins are the templates the app ships, in its order.

func Merge

func Merge(builtins, custom []Template) []Template

Merge combines built-ins and custom templates into one display list: grouped by category, built-ins (and customized built-ins) before custom within a group, then alphabetical. A custom template carrying builtinId replaces that built-in.

func ParseCustom

func ParseCustom(file vault.CustomTemplateFile) Template

ParseCustom reads a custom template file: optional frontmatter (name, description, category, titleTemplate, targetFolder, targetSubpath, builtinId) plus a body. Never fails.

Jump to

Keyboard shortcuts

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