From 8bf312baa301fbb3085a9192759dd02bb02d8502 Mon Sep 17 00:00:00 2001 From: Mathis Gauthey Date: Thu, 4 Jan 2024 10:56:23 +0100 Subject: [PATCH] update: obsidian-omnivore config Added personalized frontmatter template for archived date feature --- .obsidian/plugins/obsidian-omnivore/data.json | 10 ++-- .obsidian/plugins/obsidian-omnivore/main.js | 58 ++++++++++++++----- .../plugins/obsidian-omnivore/manifest.json | 2 +- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/.obsidian/plugins/obsidian-omnivore/data.json b/.obsidian/plugins/obsidian-omnivore/data.json index c53c838..c0a8582 100644 --- a/.obsidian/plugins/obsidian-omnivore/data.json +++ b/.obsidian/plugins/obsidian-omnivore/data.json @@ -8,16 +8,16 @@ "template": "# {{{title}}}\n\n#Omnivore\n\n[Read on Omnivore]({{{omnivoreUrl}}})\n[Read Original]({{{originalUrl}}})\n\n{{#note}}\n## Notes\n\n{{{note}}}\n{{/note}}\n\n{{#highlights.length}}\n## Highlights\n\n{{#highlights}}\n> {{{text}}} [⤴️]({{{highlightUrl}}}) {{#labels}} #{{name}} {{/labels}}\n{{#note}}\n\n{{{note}}}\n{{/note}}\n\n{{/highlights}}\n{{/highlights.length}}\n## Webpage\n\n{{{content}}}", "highlightOrder": "LOCATION", "syncing": false, - "folder": "_Sources/{{{date}}}", + "folder": "_Sources", "folderDateFormat": "yyyy-MM-dd", "endpoint": "https://api-prod.omnivore.app/api/graphql", "filename": "{{{title}}}", "filenameDateFormat": "yyyy-MM-dd", "attachmentFolder": "_Sources/attachments", - "version": "1.6.0", + "version": "1.8.1", "isSingleFile": false, - "frequency": 0, - "intervalId": 0, + "frequency": 5, + "intervalId": 7, "frontMatterVariables": [ "title", "author", @@ -28,5 +28,5 @@ "date_read", "date_archived" ], - "frontMatterTemplate": "" + "frontMatterTemplate": "id: {{{id}}}\ntitle: >\n {{{title}}}\n{{#author}}\nauthor: >\n {{{author}}}\n{{/author}}\n{{#labels.length}}\ntags:\n{{#labels}} - {{{name}}}\n{{/labels}}\n{{/labels.length}}\nstate: {{{state}}}\ndate_published: {{{datePublished}}}\ndate_saved: {{{dateSaved}}}\ndate_read: {{{dateRead}}}\ndate_archived: {{#formatDate}}{{{dateArchived}}},\"yyyy-MM-dd HH:mm:ss\"{{/formatDate}}" } \ No newline at end of file diff --git a/.obsidian/plugins/obsidian-omnivore/main.js b/.obsidian/plugins/obsidian-omnivore/main.js index cbd0279..206f765 100644 --- a/.obsidian/plugins/obsidian-omnivore/main.js +++ b/.obsidian/plugins/obsidian-omnivore/main.js @@ -10910,6 +10910,7 @@ var loadArticles = async (endpoint, apiKey, after = 0, first = 10, updatedAt = " isArchived readingProgressPercent archivedAt + contentReader highlights { id quote @@ -10918,9 +10919,11 @@ var loadArticles = async (endpoint, apiKey, after = 0, first = 10, updatedAt = " updatedAt type highlightPositionPercent + highlightPositionAnchorIndex labels { name } + color } labels { name @@ -12384,19 +12387,33 @@ function upperCaseFirst() { return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); }; } +function formatDateFunc() { + return function(text, render3) { + const [dateVariable, format] = text.split(",", 2); + const date = render3(dateVariable); + if (!date) { + return ""; + } + return formatDate(date, format); + }; +} var functionMap = { lowerCase, upperCase, - upperCaseFirst + upperCaseFirst, + formatDate: formatDateFunc }; var renderFilename = (article, filename, dateFormat) => { + var _a; const date = formatDate(article.savedAt, dateFormat); const datePublished = article.publishedAt ? formatDate(article.publishedAt, dateFormat).trim() : void 0; const renderedFilename = mustache_default.render(filename, { title: article.title, + author: (_a = article.author) != null ? _a : "unknown-author", date, dateSaved: date, - datePublished + datePublished, + id: article.id }); return (0, import_lodash.truncate)(renderedFilename, { length: 100 @@ -12424,14 +12441,17 @@ var renderArticleContnet = async (article, template, highlightOrder, dateHighlig }); } const highlights = articleHighlights.map((highlight) => { - var _a2; + var _a2, _b2; return { text: formatHighlightQuote(highlight.quote, template), highlightUrl: `https://omnivore.app/me/${article.slug}#${highlight.id}`, highlightID: highlight.id.slice(0, 8), dateHighlighted: formatDate(highlight.updatedAt, dateHighlightedFormat), note: (_a2 = highlight.annotation) != null ? _a2 : void 0, - labels: renderLabels(highlight.labels) + labels: renderLabels(highlight.labels), + color: (_b2 = highlight.color) != null ? _b2 : "yellow", + positionPercent: highlight.highlightPositionPercent, + positionAnchorIndex: highlight.highlightPositionAnchorIndex + 1 }; }); const dateSaved = formatDate(article.savedAt, dateSavedFormat); @@ -12452,7 +12472,7 @@ var renderArticleContnet = async (article, template, highlightOrder, dateHighlig labels: renderLabels(article.labels), dateSaved, highlights, - content: article.content, + content: article.contentReader === "WEB" ? article.content : void 0, datePublished, fileAttachment, description: article.description, @@ -12517,12 +12537,14 @@ ${frontMatterYaml}---`; ${contentWithoutFrontMatter}`; }; var renderFolderName = (article, template, dateFormat) => { + var _a; const date = formatDate(article.savedAt, dateFormat); const datePublished = article.publishedAt ? formatDate(article.publishedAt, dateFormat).trim() : void 0; return mustache_default.render(template, { date, dateSaved: date, - datePublished + datePublished, + author: (_a = article.author) != null ? _a : "unknown-author" }); }; var preParseTemplate = (template) => { @@ -14200,11 +14222,7 @@ var OmnivorePlugin = class extends import_obsidian6.Plugin { } }); const iconId = "Omnivore"; - (0, import_obsidian6.addIcon)(iconId, ` - - - - `); + (0, import_obsidian6.addIcon)(iconId, ``); this.addRibbonIcon(iconId, iconId, async (evt) => { await this.fetchOmnivore(); }); @@ -14356,7 +14374,15 @@ ${newContentWithoutFrontMatter}`); }); continue; } - await this.app.vault.create(normalizedPath, content); + try { + await this.app.vault.create(normalizedPath, content); + } catch (error) { + if (error.toString().includes("File already exists")) { + new import_obsidian6.Notice(`Skipping file creation: ${normalizedPath}. Please check if you have duplicated article titles and delete the file if needed.`); + } else { + throw error; + } + } } } manualSync && new import_obsidian6.Notice("\u{1F516} Articles fetched"); @@ -14422,9 +14448,9 @@ var OmnivoreSettingTab = class extends import_obsidian6.PluginSettingTab { }); new import_obsidian6.Setting(containerEl).setName("Custom query").setDesc(createFragment((fragment) => { fragment.append("See ", fragment.createEl("a", { - text: "https://omnivore.app/help/search", - href: "https://omnivore.app/help/search" - }), " for more info on search query syntax"); + text: "https://docs.omnivore.app/using/search", + href: "https://docs.omnivore.app/using/search" + }), " for more info on search query syntax. Make sure your Filter (in the section above) is set to advanced when using a custom query."); })).addText((text) => text.setPlaceholder("Enter an Omnivore custom search query if advanced filter is selected").setValue(this.plugin.settings.customQuery).onChange(async (value) => { this.plugin.settings.customQuery = value; await this.plugin.saveSettings(); @@ -14501,7 +14527,7 @@ var OmnivoreSettingTab = class extends import_obsidian6.PluginSettingTab { this.plugin.settings.isSingleFile = value; await this.plugin.saveSettings(); })); - new import_obsidian6.Setting(containerEl).setName("Filename").setDesc("Enter the filename where the data will be stored. {{{title}}}, {{{dateSaved}}} and {{{datePublished}}} could be used in the filename").addText((text) => text.setPlaceholder("Enter the filename").setValue(this.plugin.settings.filename).onChange(async (value) => { + new import_obsidian6.Setting(containerEl).setName("Filename").setDesc("Enter the filename where the data will be stored. {{id}}, {{{title}}}, {{{dateSaved}}} and {{{datePublished}}} could be used in the filename").addText((text) => text.setPlaceholder("Enter the filename").setValue(this.plugin.settings.filename).onChange(async (value) => { this.plugin.settings.filename = value; await this.plugin.saveSettings(); })); diff --git a/.obsidian/plugins/obsidian-omnivore/manifest.json b/.obsidian/plugins/obsidian-omnivore/manifest.json index 951dd19..07ec242 100644 --- a/.obsidian/plugins/obsidian-omnivore/manifest.json +++ b/.obsidian/plugins/obsidian-omnivore/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-omnivore", "name": "Omnivore", - "version": "1.6.0", + "version": "1.8.1", "minAppVersion": "0.15.0", "description": "This is an Omnivore plugin for Obsidian.", "author": "Omnivore",