vfiles

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package vfiles maintains an SQLite index of vault files and their metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindActualFile added in v1.2.0

func FindActualFile(dir, stem, preferExt string) string

FindActualFile returns the path of stem in dir, trying preferExt first, then falling back to a glob over all extensions. Returns "" if nothing is found.

func RewriteLinks(content []byte, oldStem, newStem string, sectionPrefixes []string) []byte

RewriteLinks rewrites all wikilink and markdown-link references to oldStem so they point to newStem instead. Non-matching links are left unchanged. Leading "./" and trailing ".md" in markdown targets are preserved. sectionPrefixes is a list of directory basenames (e.g. ["notes", "journals"]) so that vault-relative links like [notes/stem] are also rewritten.

Types

type FileEntry

type FileEntry struct {
	Path      string
	Display   string
	ModTime   time.Time
	SearchKey string // stem + title + aliases, space-joined; empty = fall back to Display
	Snippet   string // non-empty on FTS search results
}

FileEntry represents a file in the vault.

func ListFiles

func ListFiles(dir string) []FileEntry

ListFiles returns all non-directory files under dir as FileEntry values.

type FileKind

type FileKind string

FileKind identifies which section of the vault a file belongs to.

const (
	KindNote     FileKind = "note"
	KindJournal  FileKind = "journal"
	KindTemplate FileKind = "template"
	KindAsset    FileKind = "asset"
)

FileKind constants for the four file categories stored in the index.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index maintains in-memory tries for fast prefix-based file completion.

func New

func New() *Index

New returns an empty Index.

func (*Index) Add

func (idx *Index) Add(path, dir string)

Add inserts the stem for path into the trie associated with dir and persists it to the DB.

func (*Index) AllAliases

func (idx *Index) AllAliases() (map[string][]string, error)

AllAliases returns a stem >> []alias map for all files.

func (*Index) AllTitles

func (idx *Index) AllTitles(kind FileKind) (map[string]string, error)

AllTitles returns a stem >> title map for all files of the given kind.

func (*Index) AssetCompletions added in v1.2.0

func (idx *Index) AssetCompletions(prefix string) []string

AssetCompletions returns asset filenames matching prefix (case-insensitive, sorted).

func (*Index) Close

func (idx *Index) Close() error

Close...well, closes the DB connection.

func (*Index) Completions

func (idx *Index) Completions(prefix, dir string) []string

Completions returns stems matching prefix (case-insensitive, sorted) from the trie associated with dir.

func (*Index) CompletionsByAlias

func (idx *Index) CompletionsByAlias(prefix string) []string

CompletionsByAlias returns stems that have an alias matching prefix (case-insensitive), sorted.

func (*Index) CompletionsByTitle

func (idx *Index) CompletionsByTitle(prefix string, kind FileKind) []string

CompletionsByTitle returns stems whose title matches prefix (case-insensitive), sorted.

func (*Index) FrontmatterFor

func (idx *Index) FrontmatterFor(stem string, kind FileKind) (map[string]string, error)

FrontmatterFor returns all scalar frontmatter fields for the given file.

func (idx *Index) InboundLinks(stem string, kind FileKind) ([]LinkRef, error)

InboundLinks returns all files that link to the given stem.

func (*Index) Load

func (idx *Index) Load(cfg *config.Config)

Load populates each trie by walking the appropriate vault directories.

func (*Index) Open

func (idx *Index) Open(cfg *config.Config) error

Open opens the vault SQLite database, loads tries from it, and stores the db handle for later use. Returns nil without error if the vault path is unset.

func (idx *Index) OutboundLinks(stem string, kind FileKind) ([]LinkRef, error)

OutboundLinks returns all files that the given stem links to.

func (*Index) Reindex

func (idx *Index) Reindex(path, dir string)

Reindex re-parses path's content and updates the DB rows for links, tags, frontmatter, and aliases. No-op when no DB is open or dir maps to "template". Intended for immediate post-save index updates.

func (*Index) Remove

func (idx *Index) Remove(path, dir string)

Remove deletes the stem for path from the trie associated with dir and removes it from the DB.

func (*Index) Rename

func (idx *Index) Rename(oldPath, newPath, dir string)

Rename updates oldPath to newPath in the trie associated with dir and updates the DB accordingly.

func (*Index) ResolveAlias

func (idx *Index) ResolveAlias(alias string) (LinkRef, bool)

ResolveAlias looks up the canonical stem for a given alias.

func (*Index) Search

func (idx *Index) Search(query string, fuzzy bool) ([]SearchHit, error)

Search runs a full-text query against indexed file bodies and returns matching hits with snippets ordered by relevance. Returns nil when no DB is open. The query string follows fts5 MATCH syntax. When fuzzy is true, bare terms are expanded with a trailing * for prefix matching.

func (*Index) StemsForTag

func (idx *Index) StemsForTag(tag string) ([]LinkRef, error)

StemsForTag returns all files carrying the given tag.

func (*Index) Sync

func (idx *Index) Sync(cfg *config.Config)

Sync performs an incremental update of the index against the filesystem. When a DB is open it reconciles disk vs stored rows; otherwise falls back to a full Load. Intended for background use after Open on startup.

func (*Index) TagsFor

func (idx *Index) TagsFor(stem string, kind FileKind) ([]string, error)

TagsFor returns all tags on the given file, sorted alphabetically.

func (idx *Index) UpdateInboundLinks(srcPath, destPath, ext string) (int, error)

UpdateInboundLinks finds every vault file that links to srcPath, rewrites those links to point to destPath, writes the files, and reindexes them. Returns the count of files actually modified. Safe to call with a nil DB (returns 0, nil). ext is the vault file extension without the leading dot.

type LinkRef

type LinkRef struct {
	Stem string
	Kind FileKind
}

LinkRef identifies one end of a link, the stem and the kind of Vault file.

type SearchHit

type SearchHit struct {
	Stem    string
	Kind    FileKind
	Snippet string // context excerpt; matched terms wrapped in << >>
}

SearchHit is returned by Index.Search.

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie is a rune-level prefix trie used for fast file-name completion.

func (*Trie) All

func (t *Trie) All() []string

All returns every key in the trie.

func (*Trie) CaseFoldPrefixMatch

func (t *Trie) CaseFoldPrefixMatch(prefix string) []string

CaseFoldPrefixMatch returns all keys whose prefix case-folds to prefix, preserving the original stored casing in the returned strings.

func (*Trie) Delete

func (t *Trie) Delete(key string) bool

Delete removes key from the trie. Returns true if the key was present. Empty intermediate nodes are pruned.

func (*Trie) Insert

func (t *Trie) Insert(key string)

Insert adds key to the trie. No-op if already present.

func (*Trie) Len

func (t *Trie) Len() int

Len returns the number of keys in the trie.

func (*Trie) PrefixMatch

func (t *Trie) PrefixMatch(prefix string) []string

PrefixMatch returns all keys with the given prefix, in no particular order.

Jump to

Keyboard shortcuts

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