Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit ec86dba

Browse files
committed
Update types
1 parent 4c883af commit ec86dba

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

server/aleph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ export class Aleph implements IAleph {
640640
for (const callback of this.#renderListeners) {
641641
callback({ path: url.toString(), html, data })
642642
}
643-
return [buildHtml(html), data]
643+
return [buildHtml(html, !this.isDev), data]
644644
}
645645

646646
/** create a fs watcher. */
@@ -720,12 +720,12 @@ export class Aleph implements IAleph {
720720
headElements: [],
721721
scripts: this.getScripts(),
722722
body: '<div id="__aleph"></div>',
723-
minify: !this.isDev
723+
bodyAttrs: {},
724724
}
725725
for (const callback of this.#renderListeners) {
726726
await callback({ path: 'spa-index-html', html, data: null })
727727
}
728-
return buildHtml(html)
728+
return buildHtml(html, !this.isDev)
729729
}
730730

731731
/** get scripts for html output */

server/renderer.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class Renderer {
147147
})
148148
],
149149
body: `<div id="__aleph">${body}</div>`,
150-
minify: !isDev
150+
bodyAttrs: {}
151151
},
152152
data
153153
]
@@ -176,15 +176,14 @@ export class Renderer {
176176
/** build html content by given descriptor */
177177
export function buildHtml({
178178
body,
179+
bodyAttrs = {},
179180
lang = 'en',
180-
headElements: head = [],
181-
bodyClassName: className,
182-
scripts = [],
183-
minify = false
184-
}: HtmlDescriptor) {
181+
headElements = [],
182+
scripts = []
183+
}: HtmlDescriptor, minify = false) {
185184
const eol = minify ? '' : '\n'
186185
const indent = minify ? '' : ' '.repeat(2)
187-
const headTags = head.map(tag => tag.trim()).concat(scripts.map(v => {
186+
const headTags = headElements.map(tag => tag.trim()).concat(scripts.map(v => {
188187
if (!util.isString(v) && util.isFilledString(v.src)) {
189188
if (v.type === 'module') {
190189
return `<link rel="modulepreload" href=${JSON.stringify(v.src)} />`
@@ -207,7 +206,7 @@ export function buildHtml({
207206
}
208207
}).filter(Boolean)
209208

210-
if (!head.some(tag => tag.trimLeft().startsWith('<meta') && tag.includes('name="viewport"'))) {
209+
if (!headElements.some(tag => tag.trimLeft().startsWith('<meta') && tag.includes('name="viewport"'))) {
211210
headTags.unshift('<meta name="viewport" content="width=device-width" />')
212211
}
213212

@@ -218,7 +217,7 @@ export function buildHtml({
218217
indent + '<meta charSet="utf-8" />',
219218
...headTags.map(tag => indent + tag),
220219
'</head>',
221-
className ? `<body class="${className}">` : '<body>',
220+
`<body${formatAttrs(bodyAttrs)}>`,
222221
indent + body,
223222
...scriptTags.map(tag => indent + tag),
224223
'</body>',

types.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,11 @@ type DependencyDescriptor = {
119119

120120
/** The HTML Descriptor. */
121121
type HtmlDescriptor = {
122-
lang?: string,
123-
headElements?: string[],
124-
body?: string,
125-
bodyClassName?: string,
126-
scripts?: (string | { id?: string, type?: string, src?: string, innerText?: string, async?: boolean, preload?: boolean, nomodule?: boolean })[],
127-
minify?: boolean
122+
lang: string,
123+
headElements: string[],
124+
scripts: (string | { id?: string, type?: string, src?: string, innerText?: string, async?: boolean, preload?: boolean, nomodule?: boolean })[],
125+
body: string,
126+
bodyAttrs: Record<string, string>,
128127
}
129128

130129
/** SSR data with expires. */

0 commit comments

Comments
 (0)