|
|
@ -26,6 +26,7 @@ export async function renderPage(
|
|
|
|
result: RollupOutput | null,
|
|
|
|
result: RollupOutput | null,
|
|
|
|
appChunk: OutputChunk | undefined,
|
|
|
|
appChunk: OutputChunk | undefined,
|
|
|
|
cssChunk: OutputAsset | undefined,
|
|
|
|
cssChunk: OutputAsset | undefined,
|
|
|
|
|
|
|
|
assets: string[],
|
|
|
|
pageToHashMap: Record<string, string>,
|
|
|
|
pageToHashMap: Record<string, string>,
|
|
|
|
hashMapString: string,
|
|
|
|
hashMapString: string,
|
|
|
|
siteDataString: string
|
|
|
|
siteDataString: string
|
|
|
@ -86,21 +87,18 @@ export async function renderPage(
|
|
|
|
preloadLinks = preloadLinks.filter((link) => shouldPreload(link, page))
|
|
|
|
preloadLinks = preloadLinks.filter((link) => shouldPreload(link, page))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const preloadLinksString = preloadLinks
|
|
|
|
const toHeadTags = (files: string[], rel: string): HeadConfig[] =>
|
|
|
|
.map((file) => {
|
|
|
|
files.map((file) => [
|
|
|
|
return `<link rel="modulepreload" href="${
|
|
|
|
'link',
|
|
|
|
EXTERNAL_URL_RE.test(file) ? '' : siteData.base // don't add base to external urls
|
|
|
|
{
|
|
|
|
}${file}">`
|
|
|
|
rel,
|
|
|
|
})
|
|
|
|
// don't add base to external urls
|
|
|
|
.join('\n ')
|
|
|
|
href: (EXTERNAL_URL_RE.test(file) ? '' : siteData.base) + file
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
const prefetchLinkString = prefetchLinks
|
|
|
|
const preloadHeadTags = toHeadTags(preloadLinks, 'modulepreload')
|
|
|
|
.map((file) => {
|
|
|
|
const prefetchHeadTags = toHeadTags(prefetchLinks, 'prefetch')
|
|
|
|
return `<link rel="prefetch" href="${
|
|
|
|
|
|
|
|
EXTERNAL_URL_RE.test(file) ? '' : siteData.base // don't add base to external urls
|
|
|
|
|
|
|
|
}${file}">`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.join('\n ')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stylesheetLink = cssChunk
|
|
|
|
const stylesheetLink = cssChunk
|
|
|
|
? `<link rel="preload stylesheet" href="${siteData.base}${cssChunk.fileName}" as="style">`
|
|
|
|
? `<link rel="preload stylesheet" href="${siteData.base}${cssChunk.fileName}" as="style">`
|
|
|
@ -109,21 +107,27 @@ export async function renderPage(
|
|
|
|
const title: string = createTitle(siteData, pageData)
|
|
|
|
const title: string = createTitle(siteData, pageData)
|
|
|
|
const description: string = pageData.description || siteData.description
|
|
|
|
const description: string = pageData.description || siteData.description
|
|
|
|
|
|
|
|
|
|
|
|
const headBeforeTransform = mergeHead(
|
|
|
|
const headBeforeTransform = [
|
|
|
|
siteData.head,
|
|
|
|
...preloadHeadTags,
|
|
|
|
filterOutHeadDescription(pageData.frontmatter.head)
|
|
|
|
...prefetchHeadTags,
|
|
|
|
)
|
|
|
|
...mergeHead(
|
|
|
|
|
|
|
|
siteData.head,
|
|
|
|
|
|
|
|
filterOutHeadDescription(pageData.frontmatter.head)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const head = mergeHead(
|
|
|
|
const head = mergeHead(
|
|
|
|
headBeforeTransform,
|
|
|
|
headBeforeTransform,
|
|
|
|
(await config.transformHead?.({
|
|
|
|
(await config.transformHead?.({
|
|
|
|
|
|
|
|
page,
|
|
|
|
siteConfig: config,
|
|
|
|
siteConfig: config,
|
|
|
|
siteData,
|
|
|
|
siteData,
|
|
|
|
pageData,
|
|
|
|
pageData,
|
|
|
|
title,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
description,
|
|
|
|
head: headBeforeTransform,
|
|
|
|
head: headBeforeTransform,
|
|
|
|
content
|
|
|
|
content,
|
|
|
|
|
|
|
|
assets
|
|
|
|
})) || []
|
|
|
|
})) || []
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -165,8 +169,6 @@ export async function renderPage(
|
|
|
|
? `<script type="module" src="${siteData.base}${appChunk.fileName}"></script>`
|
|
|
|
? `<script type="module" src="${siteData.base}${appChunk.fileName}"></script>`
|
|
|
|
: ``
|
|
|
|
: ``
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${preloadLinksString}
|
|
|
|
|
|
|
|
${prefetchLinkString}
|
|
|
|
|
|
|
|
${await renderHead(head)}
|
|
|
|
${await renderHead(head)}
|
|
|
|
</head>
|
|
|
|
</head>
|
|
|
|
<body>${teleports?.body || ''}
|
|
|
|
<body>${teleports?.body || ''}
|
|
|
@ -179,13 +181,15 @@ export async function renderPage(
|
|
|
|
|
|
|
|
|
|
|
|
await fs.ensureDir(path.dirname(htmlFileName))
|
|
|
|
await fs.ensureDir(path.dirname(htmlFileName))
|
|
|
|
const transformedHtml = await config.transformHtml?.(html, htmlFileName, {
|
|
|
|
const transformedHtml = await config.transformHtml?.(html, htmlFileName, {
|
|
|
|
|
|
|
|
page,
|
|
|
|
siteConfig: config,
|
|
|
|
siteConfig: config,
|
|
|
|
siteData,
|
|
|
|
siteData,
|
|
|
|
pageData,
|
|
|
|
pageData,
|
|
|
|
title,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
description,
|
|
|
|
head,
|
|
|
|
head,
|
|
|
|
content
|
|
|
|
content,
|
|
|
|
|
|
|
|
assets
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await fs.writeFile(htmlFileName, transformedHtml || html)
|
|
|
|
await fs.writeFile(htmlFileName, transformedHtml || html)
|
|
|
|
}
|
|
|
|
}
|
|
|
|