Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,24 @@ new AdminForth({
})
```

If you hide the logo with `showBrandLogoInSidebar: false`, components injected via `sidebarTop` will take the whole line width.
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')"
}
],
...
}

```
4 changes: 2 additions & 2 deletions adminforth/modules/codeInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>`;
: `<${tagName} ${attrs}> ${innerCode} </${tagName}>`;
}).join('\n ');

indexHtmlContent = indexHtmlContent.replace(" <!-- /* IMPORTANT:ADMINFORTH HEAD */ -->", `${renderedHead}` );
Expand Down
1 change: 1 addition & 0 deletions adminforth/spa/src/spa_types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type CoreConfig = {
customHeadItems?: {
tagName: string;
attributes: { [key: string]: string | boolean };
innerCode?: string;
}[],
}

Expand Down
2 changes: 2 additions & 0 deletions adminforth/types/Back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ interface AdminForthInputConfigCustomization {
customHeadItems?: {
tagName: string;
attributes: Record<string, string | boolean>;
innerCode?: string;
}[];

}
Expand Down Expand Up @@ -1140,6 +1141,7 @@ export interface AdminForthConfigCustomization extends Omit<AdminForthInputConfi
customHeadItems?: {
tagName: string;
attributes: Record<string, string | boolean>;
innerCode?: string;
}[];

}
Expand Down
1 change: 1 addition & 0 deletions adminforth/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ export interface AdminForthConfigForFrontend {
customHeadItems?: {
tagName: string;
attributes: Record<string, string | boolean>;
innerCode?: string;
}[],
settingPages?:{
icon?: string,
Expand Down