From 1c8eb6cbd237411c6bcbaa4cd69f353cbc5a0471 Mon Sep 17 00:00:00 2001 From: KubeSphere CI Bot <47586280+ks-ci-bot@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:43:58 +0800 Subject: [PATCH] [release-4.1] feat:Support loading styles declared by extended components (#4360) feat:support for loading styles provided by extension components Signed-off-by: lingbo Co-authored-by: lingbo --- server/controllers/view.js | 4 ++++ server/services/extension.js | 2 ++ server/views/index.html | 3 +++ 3 files changed, 9 insertions(+) diff --git a/server/controllers/view.js b/server/controllers/view.js index 17cefa3ca7b..5c4bb84e29d 100644 --- a/server/controllers/view.js +++ b/server/controllers/view.js @@ -41,6 +41,9 @@ const renderIndex = async (ctx, params) => { const dllManifest = getDllManifest(); const localeManifest = getLocaleManifest(); const importMap = getImportMap(); + const extStyles = params?.installedExtensions + ?.filter(item => !!item.styleLink) + .map(ext => ext.styleLink); await ctx.render('index', { manifest, @@ -49,6 +52,7 @@ const renderIndex = async (ctx, params) => { title: useDefaultTheme ? defaultTheme?.tabTitle : title, favicon, background, + extStyles, hostname: ctx.hostname, importMap: JSON.stringify(importMap), globals: JSON.stringify({ diff --git a/server/services/extension.js b/server/services/extension.js index b0c22351020..eeeb2dcdbfa 100644 --- a/server/services/extension.js +++ b/server/services/extension.js @@ -65,6 +65,7 @@ const getInstalledExtensions = async ctx => { const extensionName = get(item, 'metadata.labels["kubesphere.io/extension-ref"]'); const resourceVersion = get(item, 'metadata.resourceVersion'); const { link, state } = item.status; + const styleLink = item.spec.assets?.style?.link; if (state === 'Available') { const entries = extensionEntries.find(record => record.extensionName === extensionName); @@ -75,6 +76,7 @@ const getInstalledExtensions = async ctx => { name, extensionName, link, + styleLink, resourceVersion, }, entries, diff --git a/server/views/index.html b/server/views/index.html index d0fc8658642..29a255ef6d7 100644 --- a/server/views/index.html +++ b/server/views/index.html @@ -15,6 +15,9 @@ <% } %> <% if (manifest && manifest.css && manifest.css.length > 0) { %> <% manifest.css.forEach(function(item){ %> + <% }) %> <% } %> <% if (!isDev && extStyles && extStyles.length > 0) { %> <% + extStyles.forEach(function(extstyle){ %> + <% }) %> <% } %>