From 1b16fc82bc15122bba7c3545dea61b9eb725cef7 Mon Sep 17 00:00:00 2001 From: Nour Alseaf Date: Thu, 5 Sep 2024 22:05:05 +0300 Subject: [PATCH] refactored code in the skin support section under getBundleMetadata --- dump.rdb | Bin 5256 -> 5256 bytes src/meta/css.js | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/dump.rdb b/dump.rdb index f94ef692cfd53d352fec867032bebee87e7699f7..68636a904e291818bb2d94933a6efea050381872 100644 GIT binary patch delta 44 zcmeCs?9iNGAeg{#EA1CYX>n?bZf { @@ -204,24 +206,38 @@ async function getBundleMetadata(target) { path.join(utils.getFontawesomePath(), 'scss'), ]; - // Low complexitity skin support - let skin; + // Skin support + let skin = ''; let isCustomSkin = false; + if (target.startsWith('client-')) { - skin = target.split('-').slice(1).join('-'); - const isBootswatchSkin = CSS.supportedSkins.includes(skin); - isCustomSkin = !isBootswatchSkin && await CSS.isCustomSkin(skin); + const targetSkin = target.split('-').slice(1).join('-'); + const isBootswatchSkin = CSS.supportedSkins.includes(targetSkin); + + isCustomSkin = !isBootswatchSkin && await CSS.isCustomSkin(targetSkin); + skin = (isBootswatchSkin || isCustomSkin) ? targetSkin : ''; // if it's not a valid skin, don't set it + target = 'client'; - if (!isBootswatchSkin && !isCustomSkin) { - skin = ''; // invalid skin or deleted use default - } } - let themeData = null; - if (target === 'client') { - themeData = await fetchThemeData(skin, isCustomSkin); - addThemePaths(paths, themeData); - } + + let themeData = {}; + + if (target === 'client') { + themeData = await db.getObjectFields('config', ['theme:type', 'theme:id', 'useBSVariables', 'bsVariables']); + const themeId = (themeData['theme:id'] || 'nodebb-theme-harmony'); + const baseThemePath = path.join( + nconf.get('themes_path'), + (themeData['theme:type'] && themeData['theme:type'] === 'local' ? themeId : 'nodebb-theme-harmony') + ); + paths.unshift(baseThemePath); + paths.unshift(`${baseThemePath}/node_modules`); + themeData.bsVariables = parseInt(themeData.useBSVariables, 10) === 1 ? (themeData.bsVariables || '') : ''; + themeData.bootswatchSkin = skin; + themeData.isCustomSkin = isCustomSkin; + const customSkin = isCustomSkin ? await CSS.getCustomSkin(skin) : null; + themeData._variables = customSkin && customSkin._variables; + } const [scssImports, cssImports, acpScssImports] = await Promise.all([ filterGetImports(plugins.scssFiles, '.scss'),