@@ -68,22 +68,15 @@ function compileHtml(page: Page, pages: Page[]) {
6868 let html = template . body
6969
7070 // Add extra CSS or scripts
71- frontmatter . styles ??= frontmatter . style ?? ""
72- frontmatter . styles += template . frontmatter . styles ?? template . frontmatter . style ?? ""
73- if ( frontmatter . styles ) {
74- for ( const style of trimAll ( frontmatter . styles . split ( "," ) ) ) {
75- const styleTag = `<link rel="stylesheet" href="${ style } ">`
76- html = html . replace ( "</head>" , `${ indent ( styleTag ) } \n</head>` )
77- }
78- }
79- frontmatter . scripts ??= frontmatter . script ?? ""
80- frontmatter . scripts += template . frontmatter . scripts ?? template . frontmatter . script ?? ""
81- if ( frontmatter . scripts ) {
82- for ( const script of trimAll ( frontmatter . scripts . split ( "," ) ) ) {
83- const scriptTag = `<script defer src="${ script } "></script>`
84- html = html . replace ( "</body>" , `${ indent ( scriptTag ) } \n</body>` )
85- }
86- }
71+ // We accept both the singular and the plural, from both the page and the template
72+ let styles = [ frontmatter . styles , frontmatter . style , template . frontmatter . styles , template . frontmatter . style ]
73+ let scripts = [ frontmatter . scripts , frontmatter . script , template . frontmatter . scripts , template . frontmatter . script ]
74+ // combine and then filter empty values
75+ styles = trimAll ( styles . join ( "," ) . split ( "," ) ) . filter ( ( v ) => v )
76+ scripts = trimAll ( scripts . join ( "," ) . split ( "," ) ) . filter ( ( v ) => v )
77+ // insert at the end of the head
78+ for ( const style of styles ) html = html . replace ( "</head>" , ` <link rel="stylesheet" href="${ style } ">\n</head>` )
79+ for ( const script of scripts ) html = html . replace ( "</head>" , ` <script defer src="${ script } "></script>\n</head>` )
8780
8881 html = expandMacros ( html , page , pages )
8982
0 commit comments