diff --git a/adminforth/documentation/docs/tutorial/03-Customization/08-pageInjections.md b/adminforth/documentation/docs/tutorial/03-Customization/08-pageInjections.md index 7b006f4b..3c82f72c 100644 --- a/adminforth/documentation/docs/tutorial/03-Customization/08-pageInjections.md +++ b/adminforth/documentation/docs/tutorial/03-Customization/08-pageInjections.md @@ -554,4 +554,24 @@ new AdminForth({ }) ``` -If you hide the logo with `showBrandLogoInSidebar: false`, components injected via `sidebarTop` will take the whole line width. \ No newline at end of file +If you hide the logo with `showBrandLogoInSidebar: false`, components injected via `sidebarTop` will take the whole line width. + +## Custom scripts in head + +If you want to inject tags in your html head: + +```ts title='./index.ts' + +customization: { + ... + customHeadItems: [ + { + tagName: 'script', + attributes: { async: 'true', defer: 'true' }, + innerCode: "console.log('Hello from HTML head')" + } + ], +... +} + +``` \ No newline at end of file diff --git a/adminforth/modules/codeInjector.ts b/adminforth/modules/codeInjector.ts index 5a910f24..ca38cab8 100644 --- a/adminforth/modules/codeInjector.ts +++ b/adminforth/modules/codeInjector.ts @@ -570,14 +570,14 @@ class CodeInjector implements ICodeInjector { // inject heads to index.html const headItems = this.adminforth.config.customization?.customHeadItems; if(headItems){ - const renderedHead = headItems.map(({ tagName, attributes }) => { + const renderedHead = headItems.map(({ tagName, attributes, innerCode }) => { const attrs = Object.entries(attributes) .map(([key, value]) => `${key}="${value}"`) .join(' '); const isVoid = ['base', 'link', 'meta'].includes(tagName); return isVoid ? `<${tagName} ${attrs}>` - : `<${tagName} ${attrs}>`; + : `<${tagName} ${attrs}> ${innerCode} `; }).join('\n '); indexHtmlContent = indexHtmlContent.replace(" ", `${renderedHead}` ); diff --git a/adminforth/spa/src/spa_types/core.ts b/adminforth/spa/src/spa_types/core.ts index b65faf8e..5ad81bf5 100644 --- a/adminforth/spa/src/spa_types/core.ts +++ b/adminforth/spa/src/spa_types/core.ts @@ -49,6 +49,7 @@ export type CoreConfig = { customHeadItems?: { tagName: string; attributes: { [key: string]: string | boolean }; + innerCode?: string; }[], } diff --git a/adminforth/types/Back.ts b/adminforth/types/Back.ts index 08b421f2..1ca1d3e3 100644 --- a/adminforth/types/Back.ts +++ b/adminforth/types/Back.ts @@ -811,6 +811,7 @@ interface AdminForthInputConfigCustomization { customHeadItems?: { tagName: string; attributes: Record; + innerCode?: string; }[]; } @@ -1140,6 +1141,7 @@ export interface AdminForthConfigCustomization extends Omit; + innerCode?: string; }[]; } diff --git a/adminforth/types/Common.ts b/adminforth/types/Common.ts index 9f45ca87..b3805afd 100644 --- a/adminforth/types/Common.ts +++ b/adminforth/types/Common.ts @@ -1108,6 +1108,7 @@ export interface AdminForthConfigForFrontend { customHeadItems?: { tagName: string; attributes: Record; + innerCode?: string; }[], settingPages?:{ icon?: string,