Skip to content

MetadataCache.fileToLinktext method

MetadataCache › fileToLinktext

Official

Generates a linktext for a file.

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

Signature:

fileToLinktext(file: TFile, sourcePath: string, omitMdExtension?: boolean | undefined): string

Parameters:

ParameterTypeDescription
fileTFileThe file.
sourcePathstringThe path of the file where the link will be inserted, used to generate relative paths.
omitMdExtension?boolean | undefinedWhether to omit the .md extension.

Returns: string

Example:

console.log(metadataCache.fileToLinktext(file, 'baz/qux.md')); // 'bar' or 'foo/bar' depending on whether the file name is unique