From dc92a38ef1da4cecfc8ad951c7cf1d068b75e6b3 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 30 May 2023 13:19:38 +0800 Subject: [PATCH] fix: download content and file attachment only if included in the template --- src/main.ts | 12 +++++++++--- src/settings/template.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 6c361e7..1296be4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -196,7 +196,13 @@ export default class OmnivorePlugin extends Plugin { manualSync && new Notice("🚀 Fetching articles ..."); // pre-parse template - preParseTemplate(template); + const templateSpans = preParseTemplate(template); + const includeContent = templateSpans.some( + (templateSpan) => templateSpan[1] === "content" + ); + const includeFileAttachment = templateSpans.some( + (templateSpan) => templateSpan[1] === "fileAttachment" + ); const size = 50; for ( @@ -211,7 +217,7 @@ export default class OmnivorePlugin extends Plugin { size, parseDateTime(syncAt).toISO(), getQueryFromFilter(filter, customQuery), - true, + includeContent, "highlightedMarkdown" ); @@ -229,7 +235,7 @@ export default class OmnivorePlugin extends Plugin { await this.app.vault.createFolder(folderName); } const fileAttachment = - article.pageType === PageType.File + article.pageType === PageType.File && includeFileAttachment ? await this.downloadFileAsAttachment(article) : undefined; const content = await renderArticleContnet( diff --git a/src/settings/template.ts b/src/settings/template.ts index 3397f1a..0610cf5 100644 --- a/src/settings/template.ts +++ b/src/settings/template.ts @@ -298,5 +298,5 @@ export const renderFolderName = (folder: string, folderDate: string) => { }; export const preParseTemplate = (template: string) => { - Mustache.parse(template); + return Mustache.parse(template); };