note

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package note implements nt's markdown notes with light YAML frontmatter (SPEC §5). Notes are one file each under notes/, so they need no shared lock: creation and edits are atomic single-file writes.

Index

Constants

View Source
const TaskNoteFolder = "tasks"

TaskNoteFolder is the subfolder under notes/ where a task's "body" notes live (auto-split paragraph captures and explicit task detail). Grouping them keeps these machine-created notes out of a human's hand-curated folders — like the "journal" folder does for daily notes.

Variables

This section is empty.

Functions

func Slug

func Slug(title string) string

Slug derives a filesystem-safe slug from a title, falling back to a timestamp when the title yields nothing usable (à la nb).

Types

type Cache added in v0.4.0

type Cache struct {
	// contains filtered or unexported fields
}

Cache is an mtime-keyed parse cache for note files. List walks notes/ but only re-reads and re-parses files whose size or mtime changed since last time — turning a snapshot rebuild from "read+parse every note" into "stat every note, read+parse the few that changed". This is what lets the in-memory read-model scale to thousands of notes (a single edit no longer re-reads the whole store).

Returned *Note values are shared with the cache; the read-model treats them as read-only, so this is safe. Cache is safe for concurrent use.

func NewCache added in v0.4.0

func NewCache() *Cache

NewCache returns an empty note cache.

func (*Cache) List added in v0.4.0

func (c *Cache) List(s *store.Store) ([]*Note, error)

List returns all notes under notes/, reusing unchanged files from the cache and re-parsing only those that were added or modified. Deleted files are evicted. Output ordering matches note.List (by Rel).

type Note

type Note struct {
	Path     string
	Rel      string // path relative to notes/ (slash-separated), set by List
	ID       string
	Title    string
	Tags     []string
	Aliases  []string
	Source   string
	Created  string
	Updated  string // stamped when nt rewrites the note (retag, --field)
	Archived bool   // frontmatter archived: true — retired from active views, still on disk
	Favorite bool   // frontmatter favorite: true — starred/pinned for quick access
	Body     string
	Extra    []string // raw frontmatter lines for keys nt doesn't model (preserved verbatim)
}

Note is a parsed markdown note.

func Active added in v0.12.0

func Active(ns []*Note) []*Note

List loads all notes in the store's notes directory, recursing into subfolders so an Obsidian-style nested vault works. Hidden dirs (.obsidian/, .trash/, .git/) and non-.md files are skipped. Each note's Rel (path relative to notes/, slash-separated) is set for link resolution; results are sorted by Rel for deterministic ordering. Active drops archived notes — the working set, for views/search that should hide retired notes. List itself returns everything (archived included) so link-rewriting and the archived view still see them.

func Create

func Create(s *store.Store, title, body string, tags []string, source, folder string) (*Note, error)

Create builds and writes a new note, returning it. The body is prefixed with an H1 title when it doesn't already start with one. Create writes a new note. folder, when non-empty, is a slash-separated subfolder under notes/ (e.g. "work" or "work/auth"); it is created as needed. The filename is slugged from the title; the body and frontmatter are written by Save.

func List

func List(s *store.Store) ([]*Note, error)

func Load

func Load(path string) (*Note, error)

Load parses a note file (frontmatter + body). Unknown frontmatter keys are ignored, not an error.

func (*Note) Save

func (n *Note) Save() error

Save writes the note atomically with frontmatter.

Jump to

Keyboard shortcuts

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