topic

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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, …).

View Source
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.

func SaveLast

func SaveLast(path string) error

SaveLast records path as the most recently chosen topic, keeping up to recentMax earlier ones behind it. Failures are returned but are non-fatal to callers — losing the "jump back" hint is benign.

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

func ParseName(s string) (Name, error)

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

func Create(root, rawName string, now time.Time) (Topic, error)

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

func New(root, arg string) (t Topic, created bool, err error)

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

func PinRecent(ts []Topic, recent []string) []Topic

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

func Resolve(root, arg string) (matches []Topic, created bool, err error)

Resolve finds the topic(s) under root matching arg, creating one when nothing matches at all:

  1. Exact match on Name or DirName (compared by matchKey), or on Path for an absolute arg, wins outright — one result, nothing created.
  2. 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.
  3. 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

func Scan(root string) ([]Topic, error)

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

func (t Topic) MainNote() string

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

func (t Topic) TSVRow(last string) string

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.

Jump to

Keyboard shortcuts

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