Skip to content

Commit 36c59ea

Browse files
author
yaroslav8765
committed
feat: add docs for the customHeadItems
1 parent d9da154 commit 36c59ea

File tree

6 files changed

+51
-3
lines changed

6 files changed

+51
-3
lines changed

adminforth/documentation/docs/tutorial/03-Customization/01-branding.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,37 @@ auth: {
169169
`loginBackgroundPosition` accepts values:
170170

171171
- `over` - image will be over the whole login page with cover mode
172-
- `1/2`(default), `3/4`, `2/5`, `3/5` etc. - image will be in the left side of the login page with cover mode
172+
- `1/2`(default), `3/4`, `2/5`, `3/5` etc. - image will be in the left side of the login page with cover mode
173+
174+
## Custom items in html head
175+
176+
If you want to add custom elements to the HTML head, you can define them in the configuration:
177+
178+
```ts title='./index.ts'
179+
customization: {
180+
customHeadItems: [
181+
{
182+
tagName: 'link',
183+
attributes: {
184+
rel: 'stylesheet',
185+
href: 'https://example.com/custom.css'
186+
}
187+
},
188+
{
189+
tagName: 'script',
190+
attributes: {
191+
src: 'https://example.com/custom.js',
192+
defer: true
193+
}
194+
},
195+
{
196+
tagName: 'meta',
197+
attributes: {
198+
name: 'theme-color',
199+
content: ' #000000'
200+
}
201+
}
202+
]
203+
}
204+
205+
```

adminforth/modules/codeInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ class CodeInjector implements ICodeInjector {
547547
);
548548

549549
// inject heads to index.html
550-
const headItems = this.adminforth.config.customization!.customHeadItems;
550+
const headItems = this.adminforth.config.customization?.customHeadItems;
551551
const renderedHead = headItems.map(({ tagName, attributes }) => {
552552
const attrs = Object.entries(attributes)
553553
.map(([k, v]) => `${k}="${v}"`)

adminforth/modules/restApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
224224
},
225225
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
226226
singleTheme: this.adminforth.config.customization.singleTheme,
227+
customHeadItems: this.adminforth.config.customization.customHeadItems,
227228
};
228229
},
229230
});
@@ -303,6 +304,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
303304
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
304305
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
305306
singleTheme: this.adminforth.config.customization.singleTheme,
307+
customHeadItems: this.adminforth.config.customization.customHeadItems,
306308
}
307309

308310
const loggedInPart = {

adminforth/spa/src/spa_types/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export type CoreConfig = {
4040
show?: string,
4141
list?: string,
4242
} | string,
43+
44+
customHeadItems?: {
45+
tagName: string;
46+
attributes: { [key: string]: string | boolean };
47+
}[],
4348
}
4449

4550

adminforth/types/Back.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,10 @@ interface AdminForthInputConfigCustomization {
765765
everyPageBottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
766766
}
767767

768+
/**
769+
* Allows adding custom elements (e.g., <link>, <script>, <meta>) to the <head> of the HTML document.
770+
* Each item must include a tag name and a set of attributes.
771+
*/
768772
customHeadItems?: {
769773
tagName: string;
770774
attributes: Record<string, string | boolean>;

adminforth/types/Common.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,11 @@ export interface AdminForthConfigForFrontend {
10811081
header: Array<AdminForthComponentDeclarationFull>,
10821082
sidebar: Array<AdminForthComponentDeclarationFull>,
10831083
everyPageBottom: Array<AdminForthComponentDeclarationFull>,
1084-
}
1084+
},
1085+
customHeadItems?: {
1086+
tagName: string;
1087+
attributes: Record<string, string | boolean>;
1088+
}[],
10851089
}
10861090

10871091
export interface GetBaseConfigResponse {

0 commit comments

Comments
 (0)