From e1cbc569f097367690434257eba5512a48d638eb Mon Sep 17 00:00:00 2001 From: YISH Date: Tue, 17 May 2022 22:29:32 +0800 Subject: [PATCH] :art: Adjust settings to save only the changed parts --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 23 +++++++++++++++++++---- versions.json | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/manifest.json b/manifest.json index a250634..d3e2e95 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-enhancing-export", "name": "Obsidian Enhancing Export", - "version": "1.0.8", + "version": "1.0.9", "minAppVersion": "0.12.0", "description": "This is a enhancing export plugin for Obsidian. It allows to export to formats like Html, DOCX, ePub and PDF or Markdown(Hugo) etc.", "author": "YISH", diff --git a/package.json b/package.json index aa1acce..a02a997 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-enhancing-export", - "version": "1.0.8", + "version": "1.0.9", "description": "This is a enhancing export plugin for Obsidian. It allows to export to formats like Html, DOCX, ePub and PDF or Markdown(Hugo) etc.", "main": "dist/main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index abfc0a0..b4f9b89 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ import luaScripts from './lua'; import { App, Menu, Plugin, PluginManifest, TFile, Notice } from 'obsidian'; -import { UniversalExportPluginSettings, DEFAULT_SETTINGS, getPlatformValue } from './settings'; +import { UniversalExportPluginSettings, ExportSetting, DEFAULT_SETTINGS, getPlatformValue } from './settings'; import { ExportDialog } from './ui/export_dialog'; import { ExportSettingTab } from './ui/setting_tab'; import lang, { Lang } from './lang'; @@ -17,7 +17,7 @@ export default class UniversalExportPlugin extends Plugin { async onload() { await this.loadSettings(); - const { lang, settings: globalSetting } = this; + const { lang } = this; this.addSettingTab(new ExportSettingTab(this.app, this)); @@ -83,7 +83,11 @@ export default class UniversalExportPlugin extends Plugin { } public async loadSettings(): Promise { - this.settings = Object.assign({}, JSON.parse(JSON.stringify(DEFAULT_SETTINGS)), await this.loadData()); + const settings: UniversalExportPluginSettings = Object.assign({}, await this.loadData()); + settings.items.forEach(v => { + Object.assign(v, DEFAULT_SETTINGS.items.find(o => o.name === v.name) ?? {}, v); + }); + this.settings = settings; if (this.settings.version !== this.manifest.version) { await this.saveLuaScripts(); this.settings.version = this.manifest.version; @@ -93,7 +97,18 @@ export default class UniversalExportPlugin extends Plugin { public async saveSettings(): Promise { console.log('[obsidian-enhancing-export] saveSettings', this.settings); - await this.saveData(this.settings); + const settings: UniversalExportPluginSettings = JSON.parse(JSON.stringify(this.settings)); + settings.items.forEach(v => { + const def = DEFAULT_SETTINGS.items.find(o => o.name === v.name); + if (def) { + Object.keys(v).forEach((k: keyof ExportSetting) => { + if (k !== 'name' && v[k] === def[k]) { + delete v[k]; + } + }); + } + }); + await this.saveData(settings); } async saveLuaScripts(): Promise { diff --git a/versions.json b/versions.json index 5597eb9..8a104ad 100644 --- a/versions.json +++ b/versions.json @@ -3,5 +3,6 @@ "1.0.5": "0.12.0", "1.0.6": "0.12.0", "1.0.7": "0.12.0", - "1.0.8": "0.12.0" + "1.0.8": "0.12.0", + "1.0.9": "0.12.0" } \ No newline at end of file