From 5328c588fffeea0f29b9c8daf3c02ea58634b048 Mon Sep 17 00:00:00 2001 From: Mara-Li Date: Fri, 29 Dec 2023 06:27:07 +0100 Subject: [PATCH] fix(dataview): add barrage to prevent crash if no dataview found --- src/conversion/compiler/dataview.ts | 4 +++- src/i18n/locales/en.json | 2 +- src/i18n/locales/fr.json | 2 +- src/settings.ts | 7 ++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/conversion/compiler/dataview.ts b/src/conversion/compiler/dataview.ts index c3b14bf5..6665900a 100644 --- a/src/conversion/compiler/dataview.ts +++ b/src/conversion/compiler/dataview.ts @@ -37,7 +37,9 @@ export async function convertDataviewQueries( ): Promise { let replacedText = text; const dataViewRegex = /```dataview\s(.+?)```/gsm; - if (!isPluginEnabled(app)) return replacedText; + //@ts-ignore + const isDataviewEnabled = app.plugins.plugins.dataview; + if (!isDataviewEnabled || !isPluginEnabled(app)) return replacedText; const dvApi = getAPI(); if (!dvApi) return replacedText; const matches = text.matchAll(dataViewRegex); diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 465e7db2..becadf52 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -157,7 +157,7 @@ "settings": { "conversion": { "dataview": { - "desc": "Convert dataview to markdown.", + "desc": "Convert dataview to markdown. Only works if Dataview is enabled.", "title": "Dataview" }, "desc": "Theses option won't change the content of the file in your Obsidian Vault, but will change the content of the file in GitHub.", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 046ff67b..9035dcd1 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -157,7 +157,7 @@ "settings": { "conversion": { "dataview": { - "desc": "Convertir les requêtes Dataview en markdown.", + "desc": "Convertir les requêtes Dataview en markdown. Ne fonctionne que si Dataview est activé.", "title": "Dataview" }, "desc": "Ces options ne changent pas le contenu du fichier dans votre coffre Obsidian, mais changeront le contenu du fichier publié sur GitHub.", diff --git a/src/settings.ts b/src/settings.ts index c3d44af5..70b447f3 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -737,18 +737,23 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); + //@ts-ignore + const isDataviewEnabled = this.app.plugins.plugins.dataview; new Setting(this.settingsPage) .setName(i18next.t("settings.conversion.dataview.title")) .setDesc(i18next.t("settings.conversion.dataview.desc")) .addToggle((toggle) => { toggle - .setValue(textSettings.dataview) + .setValue(textSettings.dataview && isDataviewEnabled) + .setDisabled(!isDataviewEnabled) .onChange(async (value) => { textSettings.dataview = value; await this.plugin.saveSettings(); }); }); + + new Setting(this.settingsPage) .setName(i18next.t("settings.regexReplacing.modal.title.text")) .setDesc(i18next.t("settings.regexReplacing.modal.desc"))