Documentation
¶
Overview ¶
Package topic discovers and creates topics laid out as <root>/<YYYY-MM-DD>-<name>/<name>.md. See GLOSSARY.md for the vocabulary and docs/concepts.md for the ideas behind the layout.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyName = errors.New("topic name is empty")
ErrEmptyName is returned by Resolve and Create when the name is blank, or has nothing left once symbols are replaced.
var ErrInvalidName = errors.New("invalid topic name")
ErrInvalidName is returned by Resolve and Create when the name holds a control character or is one Windows reserves (CON, NUL, COM1, …).
var ErrNotFound = errors.New("no topic found at that path")
ErrNotFound is returned by Resolve when arg looks like an absolute path but does not match any existing topic. Resolve never creates a directory at an arbitrary absolute path, so this is the terminal outcome for that case.
Functions ¶
func Recent ¶
func Recent() []string
Recent returns the recently chosen topic paths, newest first. Paths whose directory no longer exists are dropped, so the result may be empty.
func Root ¶
func Root() string
Root returns the topic root: $DW_ROOT if set, else ~/dw. There is no config file — this environment variable is the only knob.
The result is always made absolute. Every path dw prints is documented as absolute (see the TSV contract in main.go), and a relative DW_ROOT would break that promise in a way that compounds: the shell wrapper cd's into a resolved topic, so the next invocation would resolve the same relative DW_ROOT underneath it, nesting roots deeper on every visit.
Types ¶
type Name ¶
type Name struct {
Title string // as typed, in NFC with runs of spaces collapsed: the main note's H1
Slug string // what the directory and the main note are named
}
Name is a topic name in the two forms dw needs.
func ParseName ¶
ParseName turns what the user typed into a Name. The Slug is safe to type unquoted in a shell and to link from Obsidian: each run of spaces, replacedChars and invisible format characters (zero-width space, bidi overrides) becomes one "-", and leading or trailing "-" and "." are dropped. Case, Japanese and a "." inside the name (vs., v2.40) are kept.
Everything is NFC first, so a name some macOS tool stored decomposed (NFD) is the same name as the one typed normally.
The Slug may still be one no new topic can take (see creatable): an older topic named "CON" or "!!!" has to stay reachable by name.
type Topic ¶
type Topic struct {
DirName string // directory name, e.g. "2026-10-24-調べ方を設計する"
Name string // topic name: DirName without the date prefix, e.g. "調べ方を設計する"
Date string // "2026-10-24", or "" when the dir has no date prefix
Path string // absolute path
}
Topic is a single directory directly under the root.
func Create ¶
Create makes <root>/<date>-<slug>/<slug>.md, the main note holding nothing but the name's Title as its H1. now supplies the date so callers/tests stay deterministic.
func New ¶
New is Resolve without the partial-match step: it opens the topic whose name matches arg exactly, and otherwise creates one, even when arg is part of an existing name. That is the only way to make "アーキ定例" once "アーキ定例 10-28" exists. An exact match still opens rather than duplicates, so names stay unique.
func PinRecent ¶
PinRecent moves the topics whose Path is in recent to the front of ts, in recent's order, leaving the rest in their existing order. Used for the bare `dw` listing. Paths in recent that aren't in ts are ignored.
func Resolve ¶
Resolve finds the topic(s) under root matching arg, creating one when nothing matches at all:
- Exact match on Name or DirName (compared by matchKey), or on Path for an absolute arg, wins outright — one result, nothing created.
- Otherwise, partial match on Name (compared by matchKey): one result if there's exactly one, or every match (fzf's job to disambiguate) if there's more.
- Otherwise, a new topic is created.
Matching an existing name before creating is what keeps topic names unique within the root. An absolute arg that doesn't exactly match an existing topic returns ErrNotFound instead — Resolve never creates a directory at an arbitrary absolute path.
created reports whether Resolve made a new directory. Callers should call SaveLast only when Resolve returns exactly one match — see main.go.
func Scan ¶
Scan lists the topics directly under root (one level, no hierarchy). Dot-directories (.git, .obsidian, …) are skipped. Directories without a date prefix are still returned, with Date == "", so they are never silently dropped — sortTopics just puts them last.
func (Topic) MainNote ¶
MainNote returns the path of the note named after the topic. It may not exist: topics made by hand or by older versions of dw are still topics.
func (Topic) TSVRow ¶
TSVRow formats t as one line of dw's stdout contract:
<absolute path>\t<marker + directory name>
last is the most recently visited path (Recent()[0]); when it equals t.Path the marker is "* ", otherwise two spaces. The wrapper hides the path column from fzf, so the second column is both what is shown and what is searched.