Documentation
¶
Overview ¶
Package links implements the unified cross-item linking model (SPEC §5.1): a single [[target]] syntax that resolves to a note (by slug, title, or id) or a task (by ULID / short prefix), plus backlinks computed on demand by scanning files — no stored index.
Index ¶
- func Backlinks(s *store.Store, id, rel string) []search.Hit
- func NormalizeTarget(raw string) (key, alias string)
- func RewriteLine(s, oldRel, newBase string) (string, bool)
- func StripLine(s, targetRel string) (string, bool)
- func SuffixMatch(noteRel, targetKey string) bool
- func Wikilinks(s string) []string
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Backlinks ¶
Backlinks finds lines across tasks.txt and notes/ that link TO the item with the given id and rel (rel = a note's path relative to notes/, empty for tasks). It excludes the item's own defining line. A coarse ripgrep pass is refined in Go so `id:` self-definitions and substring false-positives are filtered out, and so a [work/auth] / [[auth|alias]] link to this note counts.
func NormalizeTarget ¶
NormalizeTarget reduces a raw [[…]] inner string to a resolution key and the optional display alias: it strips a |alias, a #heading / #^block fragment, and a trailing .md, but KEEPS any folder/ prefix so suffix matching can use it.
func RewriteLine ¶
RewriteLine rewrites every [[…]] in s that resolves (by path-suffix) to the note at oldRel so its basename becomes newBase, preserving any folder prefix, #fragment, and |alias. Returns the new string and whether anything changed.
func StripLine ¶ added in v0.16.0
StripLine replaces every [[…]] in s that resolves to the note at targetRel with its plain display text (the |alias if present, else the link name), so the referencing line keeps reading naturally after the target is deleted instead of carrying a dangling link. It matches title-form links too (suffixMatchSlug), the same way backlink discovery does. Returns the new string and whether anything changed.
func SuffixMatch ¶
SuffixMatch reports whether targetKey matches noteRel by shortest path-suffix — exported for adapters that list candidates for an ambiguous link (the web viewer's "did you mean" page) without duplicating the resolution rule.
Types ¶
type Item ¶
type Item struct {
Kind string // "task" | "note"
ID string
Title string
Path string // notes only
}
Item is a resolved link target.
func Resolve ¶
Resolve maps a [[target]] to an item: note by path-suffix → note title → note id → task ULID. Obsidian resolves links by filename and disambiguates by the shortest path, so `[[auth]]` matches any note named auth.md while `[work/auth]` matches only one under work/. A bare name that matches several notes resolves to an Item{Kind:"ambiguous"} with ok=false (callers surface it for the user to qualify) rather than silently guessing.