links

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backlinks(s *store.Store, id, rel string) []search.Hit

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

func NormalizeTarget(raw string) (key, alias string)

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

func RewriteLine(s, oldRel, newBase string) (string, bool)

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

func StripLine(s, targetRel string) (string, bool)

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

func SuffixMatch(noteRel, targetKey string) bool

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.

func Wikilinks(s string) []string

Wikilinks returns the raw inner strings of every [[…]] in s (exported for adapters that need a note's outbound links, e.g. the MCP nt_links tool).

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

func Resolve(target string, doc *task.Doc, notes []*note.Note) (Item, bool)

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.

Jump to

Keyboard shortcuts

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