From ef50769fd8964fed5de4952b10893842b5d14cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Thu, 28 Dec 2023 11:47:12 +0900 Subject: [PATCH] fix(config): omit null value from book.json --- src/index.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7ecb57c..6ccc457 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,15 +26,23 @@ let plantUMLServer: PlantUMLServer | null = null; let libConfig: LibConfig | null = null; let classConfig: ClassConfig | null = null; +const mergeConfig = ( + defaultConfig: PluginConfig, + config: Partial, +): PluginConfig => ({ + ...defaultConfig, + ...Object.fromEntries( + Object.entries(config).filter((_, value) => null != value), + ), +}); + export const hooks = { init: function (this: any) { - const mergedConfig = Object.assign( - {}, - defaultConfig, - this.config.get('pluginsConfig.plantuml-server') as PluginConfig, + const mergedConfig = mergeConfig(defaultConfig, { + ...this.config.get('pluginsConfig.plantuml-server'), // ebook-convert cannot handle svg format data-uri, so it is forced to change to png - this.output.name === 'ebook' ? { format: 'png' } : {}, - ); + ...(this.output.name === 'ebook' ? { format: 'png' } : {}), + }); libConfig = { optimizeImage: mergedConfig.optimizeImage,