Documentation
¶
Overview ¶
Package vfiles maintains an SQLite index of vault files and their metadata.
Index ¶
- func FindActualFile(dir, stem, preferExt string) string
- func RewriteLinks(content []byte, oldStem, newStem string, sectionPrefixes []string) []byte
- type FileEntry
- type FileKind
- type Index
- func (idx *Index) Add(path, dir string)
- func (idx *Index) AllAliases() (map[string][]string, error)
- func (idx *Index) AllTitles(kind FileKind) (map[string]string, error)
- func (idx *Index) AssetCompletions(prefix string) []string
- func (idx *Index) Close() error
- func (idx *Index) Completions(prefix, dir string) []string
- func (idx *Index) CompletionsByAlias(prefix string) []string
- func (idx *Index) CompletionsByTitle(prefix string, kind FileKind) []string
- func (idx *Index) FrontmatterFor(stem string, kind FileKind) (map[string]string, error)
- func (idx *Index) InboundLinks(stem string, kind FileKind) ([]LinkRef, error)
- func (idx *Index) Load(cfg *config.Config)
- func (idx *Index) Open(cfg *config.Config) error
- func (idx *Index) OutboundLinks(stem string, kind FileKind) ([]LinkRef, error)
- func (idx *Index) Reindex(path, dir string)
- func (idx *Index) Remove(path, dir string)
- func (idx *Index) Rename(oldPath, newPath, dir string)
- func (idx *Index) ResolveAlias(alias string) (LinkRef, bool)
- func (idx *Index) Search(query string, fuzzy bool) ([]SearchHit, error)
- func (idx *Index) StemsForTag(tag string) ([]LinkRef, error)
- func (idx *Index) Sync(cfg *config.Config)
- func (idx *Index) TagsFor(stem string, kind FileKind) ([]string, error)
- func (idx *Index) UpdateInboundLinks(srcPath, destPath, ext string) (int, error)
- type LinkRef
- type SearchHit
- type Trie
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindActualFile ¶ added in v1.2.0
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 ¶
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.
type FileKind ¶
type FileKind string
FileKind identifies which section of the vault a file belongs to.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index maintains in-memory tries for fast prefix-based file completion.
func (*Index) Add ¶
Add inserts the stem for path into the trie associated with dir and persists it to the DB.
func (*Index) AllAliases ¶
AllAliases returns a stem >> []alias map for all files.
func (*Index) AssetCompletions ¶ added in v1.2.0
AssetCompletions returns asset filenames matching prefix (case-insensitive, sorted).
func (*Index) Completions ¶
Completions returns stems matching prefix (case-insensitive, sorted) from the trie associated with dir.
func (*Index) CompletionsByAlias ¶
CompletionsByAlias returns stems that have an alias matching prefix (case-insensitive), sorted.
func (*Index) CompletionsByTitle ¶
CompletionsByTitle returns stems whose title matches prefix (case-insensitive), sorted.
func (*Index) FrontmatterFor ¶
FrontmatterFor returns all scalar frontmatter fields for the given file.
func (*Index) InboundLinks ¶
InboundLinks returns all files that link to the given stem.
func (*Index) Open ¶
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 (*Index) OutboundLinks ¶
OutboundLinks returns all files that the given stem links to.
func (*Index) Reindex ¶
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 ¶
Remove deletes the stem for path from the trie associated with dir and removes it from the DB.
func (*Index) Rename ¶
Rename updates oldPath to newPath in the trie associated with dir and updates the DB accordingly.
func (*Index) ResolveAlias ¶
ResolveAlias looks up the canonical stem for a given alias.
func (*Index) Search ¶
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 ¶
StemsForTag returns all files carrying the given tag.
func (*Index) Sync ¶
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) UpdateInboundLinks ¶
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 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) CaseFoldPrefixMatch ¶
CaseFoldPrefixMatch returns all keys whose prefix case-folds to prefix, preserving the original stored casing in the returned strings.
func (*Trie) Delete ¶
Delete removes key from the trie. Returns true if the key was present. Empty intermediate nodes are pruned.
func (*Trie) PrefixMatch ¶
PrefixMatch returns all keys with the given prefix, in no particular order.