Skip to content

Commit

Permalink
fix: optimize the reading of linkedfrontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed May 11, 2024
1 parent bd92ff1 commit 3580a4c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/utils/parse_frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,22 +485,20 @@ export function getLinkedFrontmatter(
const { settings } = plugin;
const { metadataCache, vault } = plugin.app;
const linkedKey = settings.plugin.setFrontmatterKey;
if (!linkedKey || !originalFrontmatter || !sourceFile) return originalFrontmatter;
if (!linkedKey || !originalFrontmatter || !sourceFile) return undefined;
const linkedFrontmatter = originalFrontmatter?.[linkedKey];
if (!linkedFrontmatter) return originalFrontmatter;
if (!linkedFrontmatter) return undefined;
let linkedFile: undefined | string;
metadataCache.getFileCache(sourceFile)?.frontmatterLinks?.forEach((link) => {
const fieldRegex = new RegExp(`${linkedKey}(\\.\\d+)?`, "g");
if (link.key.match(fieldRegex)) {
linkedFile = link.link;
}
});
if (!linkedFile) return originalFrontmatter;
if (!linkedFile) return undefined;
const linkedFrontmatterFile = metadataCache.getFirstLinkpathDest(linkedFile, sourceFile.path) ?? vault.getAbstractFileByPath(linkedFile);
if (!linkedFrontmatterFile || !(linkedFrontmatterFile instanceof TFile)) return originalFrontmatter;
const linked = metadataCache.getFileCache(linkedFrontmatterFile)?.frontmatter;
if (!linked) return originalFrontmatter;
return linked;
if (!linkedFrontmatterFile || !(linkedFrontmatterFile instanceof TFile)) return undefined;
return metadataCache.getFileCache(linkedFrontmatterFile)?.frontmatter;
}

export function frontmatterFromFile(file: TFile | null, plugin: GithubPublisher, repo: Repository | null) {
Expand Down

0 comments on commit 3580a4c

Please sign in to comment.