Skip to content

Commit

Permalink
feat:Support loading styles declared by extended components (#4357)
Browse files Browse the repository at this point in the history
feat:support for loading styles provided by extension components

Signed-off-by: lingbo <[email protected]>
  • Loading branch information
lingbohome authored Dec 16, 2024
1 parent 5b48ec0 commit b4e4d94
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/controllers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions server/services/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -75,6 +76,7 @@ const getInstalledExtensions = async ctx => {
name,
extensionName,
link,
styleLink,
resourceVersion,
},
entries,
Expand Down
3 changes: 3 additions & 0 deletions server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<% } %> <% if (manifest && manifest.css && manifest.css.length > 0) { %> <%
manifest.css.forEach(function(item){ %>
<link href="<%= bundlePrefix %>/<%= item %>" rel="stylesheet" media="all" />
<% }) %> <% } %> <% if (!isDev && extStyles && extStyles.length > 0) { %> <%
extStyles.forEach(function(extstyle){ %>
<link href="/pstatic<%= extstyle %>" rel="stylesheet" media="all" />
<% }) %> <% } %>
</head>
<body>
Expand Down

0 comments on commit b4e4d94

Please sign in to comment.