Skip to content

MetadataCache

Linktext is any internal link that is composed of a path and a subpath, such as ‘My note#Heading’ Linkpath (or path) is the path part of a linktext Subpath is the heading/block ID part of a linktext.

Extends

Constructors

new MetadataCache()

new MetadataCache(): MetadataCache

Returns

MetadataCache

Inherited from

Events.constructor

Properties

_

_: Record<string, EventsEntry[]>

Inherited from

Events._


app

app: App

Reference to App


didFinish

didFinish: Debouncer<[], void>


resolvedLinks: Record<string, Record<string, number>>

Contains all resolved links. This object maps each source file’s path to an object of destination file paths with the link count. Source and destination paths are all vault absolute paths that comes from TFile.path and can be used with Vault.getAbstractFileByPath(path).


unresolvedLinks: Record<string, Record<string, number>>

Contains all unresolved links. This object maps each source file to an object of unknown destinations with count. Source paths are all vault absolute paths, similar to resolvedLinks.


vault

vault: Vault

Reference to Vault

Methods

_getLinkpathDest()

_getLinkpathDest(origin, path): TFile[]

Parameters

origin: string

path: string

Returns

TFile[]


fileToLinktext()

fileToLinktext(file, sourcePath, omitMdExtension?): string

Generates a linktext for a file.

If file name is unique, use the filename. If not unique, use full path.

Parameters

file: TFile

sourcePath: string

omitMdExtension?: boolean

Returns

string


getAllPropertyInfos()

getAllPropertyInfos(): Record<string, PropertyInfo>

Get all property infos of the vault

Returns

Record<string, PropertyInfo>


getBacklinksForFile()

getBacklinksForFile(file): CustomArrayDict<Reference>

Get all backlink information for a file

Parameters

file: TFile

Returns

CustomArrayDict<Reference>


getCache()

getCache(path): null | CachedMetadata

Parameters

path: string

Returns

null | CachedMetadata


getCachedFiles()

getCachedFiles(): string[]

Get paths of all files cached in the vault

Returns

string[]


getFileCache()

getFileCache(file): null | CachedMetadata

Parameters

file: TFile

Returns

null | CachedMetadata


getFileInfo()

getFileInfo(path): undefined | FileCacheEntry

Get an entry from the file cache

Parameters

path: string

Returns

undefined | FileCacheEntry


getFirstLinkpathDest()

getFirstLinkpathDest(linkpath, sourcePath): null | TFile

Get the best match for a linkpath.

Parameters

linkpath: string

sourcePath: string

Returns

null | TFile


getFrontmatterPropertyValuesForKey()

getFrontmatterPropertyValuesForKey(key): string[]

Get property values for frontmatter property key

Parameters

key: string

Returns

string[]


getLinkpathDest()

getLinkpathDest(origin, path): TFile[]

Get destination of link path

Parameters

origin: string

path: string

Returns

TFile[]


getLinks(): Record<string, Reference[]>

Get all links within the vault per file

Returns

Record<string, Reference[]>


getLinkSuggestions()

getLinkSuggestions(): LinkSuggestion[]

Get all links (resolved or unresolved) in the vault. If the note has multiple aliases, it will be returned multiple times for each alias.

Returns

LinkSuggestion[]


getTags()

getTags(): Record<string, number>

Get all tags within the vault and their usage count

Returns

Record<string, number>


iterateReferences()

iterateReferences(callback): void

Iterate over all link references in the vault with callback

Parameters

callback

Returns

void


off()

off(name, callback): void

Parameters

name: string

callback

Returns

void

Inherited from

Events.off


offref()

offref(ref): void

Parameters

ref: EventRef

Returns

void

Inherited from

Events.offref


on()

on(name, callback, ctx)

on(name, callback, ctx?): EventRef

Called when a file has been indexed, and its (updated) cache is now available.

Note: This is not called when a file is renamed for performance reasons. You must hook the vault rename event for those.

Parameters

name: "changed"

callback

ctx?: any

Returns

EventRef

Inherited from

Events.on

on(name, callback, ctx)

on(name, callback, ctx?): EventRef

Called when a file has been deleted. A best-effort previous version of the cached metadata is presented, but it could be null in case the file was not successfully cached previously.

Parameters

name: "deleted"

callback

ctx?: any

Returns

EventRef

Inherited from

Events.on

on(name, callback, ctx)

on(name, callback, ctx?): EventRef

Called when a file has been resolved for resolvedLinks and unresolvedLinks. This happens sometimes after a file has been indexed.

Parameters

name: "resolve"

callback

ctx?: any

Returns

EventRef

Inherited from

Events.on

on(name, callback, ctx)

on(name, callback, ctx?): EventRef

Called when all files has been resolved. This will be fired each time files get modified after the initial load.

Parameters

name: "resolved"

callback

ctx?: any

Returns

EventRef

Inherited from

Events.on

on(name, callback)

on(name, callback): EventRef

Called whenever the metadatacache has finished updating

Parameters

name: "finished"

callback

Returns

EventRef

Inherited from

Events.on

on(name, callback)

on(name, callback): EventRef

Called whenever the metadatacache is fully loaded in

Parameters

name: "initialized"

callback

Returns

EventRef