File tree Expand file tree Collapse file tree 5 files changed +27
-3
lines changed
documentation/docs/tutorial/03-Customization Expand file tree Collapse file tree 5 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -554,4 +554,24 @@ new AdminForth({
554554})
555555` ` `
556556
557- If you hide the logo with ` showBrandLogoInSidebar: false ` , components injected via ` sidebarTop` will take the whole line width.
557+ If you hide the logo with ` showBrandLogoInSidebar: false ` , components injected via ` sidebarTop` will take the whole line width.
558+
559+ ## Custom scripts in head
560+
561+ If you want to inject tags in your html head:
562+
563+ ` ` ` ts title= ' ./index.ts'
564+
565+ customization: {
566+ ...
567+ customHeadItems: [
568+ {
569+ tagName: ' script' ,
570+ attributes: { async: ' true' , defer: ' true' },
571+ innerCode: " console.log('Hello from HTML head')"
572+ }
573+ ],
574+ ...
575+ }
576+
577+ ` ` `
Original file line number Diff line number Diff line change @@ -570,14 +570,14 @@ class CodeInjector implements ICodeInjector {
570570 // inject heads to index.html
571571 const headItems = this . adminforth . config . customization ?. customHeadItems ;
572572 if ( headItems ) {
573- const renderedHead = headItems . map ( ( { tagName, attributes } ) => {
573+ const renderedHead = headItems . map ( ( { tagName, attributes, innerCode } ) => {
574574 const attrs = Object . entries ( attributes )
575575 . map ( ( [ key , value ] ) => `${ key } ="${ value } "` )
576576 . join ( ' ' ) ;
577577 const isVoid = [ 'base' , 'link' , 'meta' ] . includes ( tagName ) ;
578578 return isVoid
579579 ? `<${ tagName } ${ attrs } >`
580- : `<${ tagName } ${ attrs } ></${ tagName } >` ;
580+ : `<${ tagName } ${ attrs } > ${ innerCode } </${ tagName } >` ;
581581 } ) . join ( '\n ' ) ;
582582
583583 indexHtmlContent = indexHtmlContent . replace ( " <!-- /* IMPORTANT:ADMINFORTH HEAD */ -->" , `${ renderedHead } ` ) ;
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ export type CoreConfig = {
4949 customHeadItems ?: {
5050 tagName : string ;
5151 attributes : { [ key : string ] : string | boolean } ;
52+ innerCode ?: string ;
5253 } [ ] ,
5354}
5455
Original file line number Diff line number Diff line change @@ -811,6 +811,7 @@ interface AdminForthInputConfigCustomization {
811811 customHeadItems ?: {
812812 tagName : string ;
813813 attributes : Record < string , string | boolean > ;
814+ innerCode ?: string ;
814815 } [ ] ;
815816
816817}
@@ -1140,6 +1141,7 @@ export interface AdminForthConfigCustomization extends Omit<AdminForthInputConfi
11401141 customHeadItems ?: {
11411142 tagName : string ;
11421143 attributes : Record < string , string | boolean > ;
1144+ innerCode ?: string ;
11431145 } [ ] ;
11441146
11451147}
Original file line number Diff line number Diff line change @@ -1108,6 +1108,7 @@ export interface AdminForthConfigForFrontend {
11081108 customHeadItems ?: {
11091109 tagName : string ;
11101110 attributes : Record < string , string | boolean > ;
1111+ innerCode ?: string ;
11111112 } [ ] ,
11121113 settingPages ?:{
11131114 icon ?: string ,
You can’t perform that action at this time.
0 commit comments