Skip to content

Commit

Permalink
* Bug fix:
Browse files Browse the repository at this point in the history
 - The issue when multiple notes has the same name in different directories.
 - Do only the first query when multiple queries happened in the same time
  • Loading branch information
kctekn committed Oct 20, 2024
1 parent baf248e commit ec1ea85
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions src/util/CodeBlockProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,6 @@ ${result.map(v => "- [[" + v.replace(/.md$/, "") + "]]").join("\n")}
//query.result = writeContent;
return [writeContent];
}
private async checkAndGetFrontmatterTag(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) {
const tag = source.replace(/frontmatter_tag:/, '').trim();
const files = this.plugin.app.vault.getMarkdownFiles();

const matchingFiles = await Promise.all(files.map(async (file) => {
const cache = this.plugin.app.metadataCache.getCache(file.path);
if (cache?.frontmatter?.tags) {
let tags = Array.isArray(cache.frontmatter.tags)
? cache.frontmatter.tags
: [cache.frontmatter.tags];

if (tags.includes("tag-report")) {
return null; // Exclude tag-report files
}

if (tags.some(t => t.includes(tag))) {
// console.log(">>find the file have this tag: ", file.path);
return file.path;
}
}
return null;
}));

const result = matchingFiles.filter(path => path !== null) as string[];
const writeContent = `
# Total \`${result.length}\` notes with tag \`${tag}\` :
${result.map(v => "- [[" + v.replace(/.md$/, "") + "]]").join("\n")}
`;
this.writeMarkdown("frontmatter_tag: " + tag, writeContent, el, ctx);
}
private async tagProcessor(query: queryKey): Promise<Promise<string[]>[]>{
const term = query.value;
const files = this.plugin.app.vault.getMarkdownFiles();
Expand Down Expand Up @@ -178,8 +148,8 @@ ${result.map(v => "- [[" + v.replace(/.md$/, "") + "]]").join("\n")}
"\[ *Tags:* " + matches?.join(' ') + " \]\n" +
"\[ *" + contentTimeString + "* \]\n" +
(this.plugin.settings.enableParagraphLinker?
"\[ *From:* [[" + `${file.name.split(".")[0]}${randomLinker}|${file.name.split(".")[0]}]] \]\n` :
"\[ *From:* [[" + `${file.name.split(".")[0]}]] \]\n` )
"\[ *From:* [[" + `${file.path}${randomLinker}|${file.name.split(".")[0]}]] \]\n` :
"\[ *From:* [[" + `${file.path}|${file.name.split(".")[0]}]] \]\n` )
}
return retParagraph;
}
Expand Down Expand Up @@ -279,8 +249,8 @@ ${result.map(v => "- [[" + v.replace(/.md$/, "") + "]]").join("\n")}
"\[ *Tags:* " + matches?.join(' ') + " \]\n" +
"\[ *" + contentTimeString + "* \]\n" +
(this.plugin.settings.enableParagraphLinker?
"\[ *From:* [[" + `${file.name.split(".")[0]}${randomLinker}|${file.name.split(".")[0]}]] \]\n` :
"\[ *From:* [[" + `${file.name.split(".")[0]}]] \]\n` )
"\[ *From:* [[" + `${file.path}${randomLinker}|${file.name.split(".")[0]}]] \]\n` :
"\[ *From:* [[" + `${file.path}|${file.name.split(".")[0]}]] \]\n` )
}
return retParagraph;
}
Expand Down Expand Up @@ -426,8 +396,8 @@ ${result.map(v => "- [[" + v.replace(/.md$/, "") + "]]").join("\n")}
return markdownText;
}
async codeBlockProcessor(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) {
//Bypass the first pass
if ((ctx.frontmatter as any).tags === undefined) {
//Bypass the none-first pass
if ((ctx.frontmatter as any).tags !== undefined) {
return;
}

Expand Down

0 comments on commit ec1ea85

Please sign in to comment.