obsidian#FileStats TypeScript Examples
The following examples show how to use
obsidian#FileStats.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: markdown-file.ts From obsidian-dataview with MIT License | 5 votes |
/** Extract markdown metadata from the given Obsidian markdown file. */
export function parsePage(path: string, contents: string, stat: FileStats, metadata: CachedMetadata): PageMetadata {
let tags = new Set<string>();
let aliases = new Set<string>();
let fields = new Map<string, Literal[]>();
let links: Link[] = [];
// File tags, including front-matter and in-file tags.
(metadata.tags || []).forEach(t => tags.add(t.tag.startsWith("#") ? t.tag : "#" + t.tag));
// Front-matter file tags, aliases, AND frontmatter properties.
if (metadata.frontmatter) {
for (let tag of extractTags(metadata.frontmatter)) {
if (!tag.startsWith("#")) tag = "#" + tag;
tags.add(tag);
}
for (let alias of extractAliases(metadata.frontmatter) || []) aliases.add(alias);
let frontFields = parseFrontmatter(metadata.frontmatter) as Record<string, Literal>;
for (let [key, value] of Object.entries(frontFields)) addInlineField(key, value, fields);
}
// Links in metadata.
for (let rawLink of metadata.links || []) {
let parsed = EXPRESSION.embedLink.parse(rawLink.original);
if (parsed.status) links.push(parsed.value);
}
// Merge frontmatter fields with parsed fields.
let markdownData = parseMarkdown(path, contents.split("\n"), metadata);
mergeFieldGroups(fields, markdownData.fields);
return new PageMetadata(path, {
tags,
aliases,
links,
lists: markdownData.lists,
fields: finalizeInlineFields(fields),
frontmatter: metadata.frontmatter,
ctime: DateTime.fromMillis(stat.ctime),
mtime: DateTime.fromMillis(stat.mtime),
size: stat.size,
day: findDate(path, fields),
});
}
Example #2
Source File: import-impl.ts From obsidian-dataview with MIT License | 5 votes |
export function runImport(
path: string,
contents: string,
stats: FileStats,
metadata: CachedMetadata
): Partial<PageMetadata> {
return parsePage(path, contents, stats, metadata);
}