Skip to content

Commit 18f3457

Browse files
author
yaroslav8765
committed
fix: prevent error when customHeadItems is not provided
1 parent 36c59ea commit 18f3457

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,17 +548,19 @@ class CodeInjector implements ICodeInjector {
548548

549549
// inject heads to index.html
550550
const headItems = this.adminforth.config.customization?.customHeadItems;
551-
const renderedHead = headItems.map(({ tagName, attributes }) => {
551+
if(headItems){
552+
const renderedHead = headItems.map(({ tagName, attributes }) => {
552553
const attrs = Object.entries(attributes)
553554
.map(([k, v]) => `${k}="${v}"`)
554555
.join(' ');
555556
const isVoid = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr'].includes(tagName);
556557
return isVoid
557558
? `<${tagName} ${attrs}>`
558559
: `<${tagName} ${attrs}></${tagName}>`;
559-
}).join('\n ');
560+
}).join('\n ');
560561

561-
indexHtmlContent = indexHtmlContent.replace("/* IMPORTANT:ADMINFORTH HEAD */", `${renderedHead}` );
562+
indexHtmlContent = indexHtmlContent.replace(" <!-- /* IMPORTANT:ADMINFORTH HEAD */ -->", `${renderedHead}` );
563+
}
562564
await fs.promises.writeFile(indexHtmlPath, indexHtmlContent);
563565

564566
/* generate custom routes */

adminforth/spa/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
document.documentElement.classList.remove('dark')
1515
}
1616
</script> -->
17-
/* IMPORTANT:ADMINFORTH HEAD */
17+
<!-- /* IMPORTANT:ADMINFORTH HEAD */ -->
1818
</head>
1919
<body class="min-h-screen flex flex-col">
2020
<div id="app" class="grow bg-lightHtml dark:bg-darkHtml w-full"></div>

0 commit comments

Comments
 (0)