graph

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMentionNotFound = errors.New("mention not found")

ErrMentionNotFound is returned by LinkifyMention when the target line is out of range or holds no unlinked, whole-word occurrence of the name to wrap.

Functions

func FilenameFromPageName

func FilenameFromPageName(name string) string

FilenameFromPageName is the inverse of PageNameFromFilename for the cases the App needs to construct a path for: journal page names (YYYY-MM-DD → YYYY_MM_DD.md) and namespace pages (proj/nested → proj___nested.md). Returns "" for any page name whose filename shape isn't covered here — callers should fall back to a more permissive resolution (or treat it as a programmer error) in that case. Used by App.Update's "." handler to derive the journal-file path when creating today's journal on demand.

func IsJournalFilename

func IsJournalFilename(name string) bool

IsJournalFilename reports whether the filename matches Logseq's journal pattern.

func IsJournalPageName

func IsJournalPageName(name string) bool

IsJournalPageName reports whether name is a journal page name (YYYY-MM-DD). This is the form PageNameFromFilename produces; it answers "is this page a journal?" without requiring the file to exist on disk.

func LinkifyMention

func LinkifyMention(body string, line int, target string) (string, search.Span, error)

LinkifyMention wraps the first unlinked, whole-word, case-insensitive occurrence of target on the 1-based line in body as [[<matched>]]. The matched bytes are preserved verbatim (Resolve is fold-keyed, so casing need not be normalised). The splice is by absolute byte offset, so line endings (incl. CRLF) and any trailing newline are preserved untouched. span is the matched range in the original body. It returns ErrMentionNotFound when no such occurrence exists — which also guards against double-wrapping an already [[linked]] mention and against a line that changed since detection.

func PageNameFromFilename

func PageNameFromFilename(name string) string

PageNameFromFilename returns the logical page name for a Logseq filename. Journals (YYYY_MM_DD.md) become YYYY-MM-DD; namespace separator "___" becomes "/".

Types

type Index

type Index struct {
	GraphPath  string
	Pages      []PageMeta
	ByName     map[string]*PageMeta // case-preserving (filename-derived)
	ByNameFold map[string]*PageMeta // case-folded (lowercase key) — for [[ALPHA]] → Alpha
	Backlinks  map[string][]Ref
	Todos      []TodoBullet
	Journals   []string // journal page names, sorted ascending
}

Index is the read-only in-memory view of a Logseq graph.

func BuildIndex

func BuildIndex(graphPath string) (*Index, error)

BuildIndex walks <graphPath>/pages and <graphPath>/journals once and returns the populated Index. Unreadable files are logged to stderr and skipped.

func (*Index) Resolve

func (idx *Index) Resolve(name string) (*PageMeta, bool)

Resolve returns the page whose name matches name exactly, or whose case-folded form matches name's lower-case. The case-preserving PageMeta is always returned, so callers see the on-disk name.

type LinkHit

type LinkHit struct {
	Target string
	Line   int // 1-based
}

LinkHit is one wiki-link occurrence in a page body.

func ExtractWikiLinks(body string) []LinkHit

ExtractWikiLinks returns every [[link]] in body, skipping fenced code blocks. Targets like [[A|alias]] are recorded as "A". An unterminated fence in body causes following lines to be skipped — that matches how a markdown renderer would treat the rest of the page as code.

type PageMeta

type PageMeta struct {
	Name      string    // logical page name (e.g., "proj/nested" or "2026-05-24")
	Path      string    // absolute filesystem path
	IsJournal bool      //
	ModTime   time.Time // file modification time; zero if stat failed
}

PageMeta is the indexed metadata for one .md file in the graph.

type Ref

type Ref struct {
	FromPage   string
	LineNumber int    // 1-based
	Context    string // the source line, trimmed
}

Ref points from one page's body to another page name.

type TodoBullet

type TodoBullet struct {
	Page       string
	LineNumber int    // 1-based
	Marker     string // TODO | LATER | DOING | WAITING
	Priority   string // "" | "A" | "B" | "C"
	Text       string // remainder after marker (and priority), trimmed
	Ordinal    int    // 0-based index among open todos on the same page (document order)
}

TodoBullet is one open task bullet (TODO/LATER/DOING/WAITING).

type TodoHit

type TodoHit struct {
	Marker   string // TODO | LATER | DOING | WAITING
	Priority string // "" | "A" | "B" | "C"
	Text     string
	Line     int // 1-based
}

TodoHit is one open task bullet occurrence in a page body.

func ExtractTodos

func ExtractTodos(body string) []TodoHit

ExtractTodos returns open TODO/LATER/DOING/WAITING bullets in body. DONE and CANCELED are intentionally ignored (we only surface open tasks). An unterminated fence in body causes following lines to be skipped — that matches how a markdown renderer would treat the rest of the page as code.

type UnlinkedRef

type UnlinkedRef struct {
	FilePath string
	PageName string
	Line     int
	Context  string
	Match    search.Span
}

UnlinkedRef is a bare-text mention of a page elsewhere in the graph that is not already a [[link]]. PageName is the referencing page (for the row label and navigation); Match locates the mention within Context.

func FilterUnlinked

func FilterUnlinked(hits []search.Hit, target, targetPath string, read func(path string) (string, error)) []UnlinkedRef

FilterUnlinked turns raw ripgrep hits for `target` into unlinked references, dropping any hit that is in the target's own file, inside a fenced code block, or already inside a [[…]] link. read returns a file's body; a read error drops every hit from that file (we can't verify its fence state).

Jump to

Keyboard shortcuts

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