mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 09:47:48 +02:00
try to make it work
This commit is contained in:
parent
3426f848a3
commit
d0e61e8d55
4 changed files with 23 additions and 3 deletions
|
@ -36,16 +36,24 @@ function assertIsHtmlTagObject(val: unknown): asserts val is HtmlTagObject {
|
|||
}
|
||||
}
|
||||
|
||||
function absoluteToRelativeTagAttribute(name: string, value: string): string {
|
||||
if ((name === 'src' || name === 'href') && value.startsWith('/')) {
|
||||
return `.${value}`; // TODO would only work for homepage
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function htmlTagObjectToString(tag: unknown): string {
|
||||
assertIsHtmlTagObject(tag);
|
||||
const isVoidTag = (voidHtmlTags as string[]).includes(tag.tagName);
|
||||
const tagAttributes = tag.attributes ?? {};
|
||||
const attributes = Object.keys(tagAttributes)
|
||||
.map((attr) => {
|
||||
const value = tagAttributes[attr]!;
|
||||
let value = tagAttributes[attr]!;
|
||||
if (typeof value === 'boolean') {
|
||||
return value ? attr : undefined;
|
||||
}
|
||||
value = absoluteToRelativeTagAttribute(attr, value);
|
||||
return `${attr}="${escapeHTML(value)}"`;
|
||||
})
|
||||
.filter((str): str is string => Boolean(str));
|
||||
|
|
|
@ -182,6 +182,7 @@ async function generateStaticFile({
|
|||
});
|
||||
// This renders the full page HTML, including head tags...
|
||||
const fullPageHtml = renderSSRTemplate({
|
||||
pathname,
|
||||
params,
|
||||
result,
|
||||
});
|
||||
|
|
|
@ -63,9 +63,11 @@ function getScriptsAndStylesheets({
|
|||
}
|
||||
|
||||
export function renderSSRTemplate({
|
||||
pathname,
|
||||
params,
|
||||
result,
|
||||
}: {
|
||||
pathname: string;
|
||||
params: SSGParams;
|
||||
result: AppRenderResult;
|
||||
}): string {
|
||||
|
@ -96,9 +98,18 @@ export function renderSSRTemplate({
|
|||
];
|
||||
const metaAttributes = metaStrings.filter(Boolean);
|
||||
|
||||
const numberOfSlashes = pathname.match(/\//g)?.length ?? 0;
|
||||
|
||||
const local = true;
|
||||
|
||||
const localBaseUrl =
|
||||
numberOfSlashes === 1 ? `./` : '../'.repeat(numberOfSlashes - 1);
|
||||
|
||||
// console.log({pathname, numberOfSlashes, baseUrl, finalBaseUrl, headTags});
|
||||
|
||||
const data: SSRTemplateData = {
|
||||
appHtml,
|
||||
baseUrl,
|
||||
baseUrl: local ? localBaseUrl : baseUrl,
|
||||
htmlAttributes,
|
||||
bodyAttributes,
|
||||
headTags,
|
||||
|
|
|
@ -112,7 +112,7 @@ export async function createBaseConfig({
|
|||
chunkFilename: isProd
|
||||
? 'assets/js/[name].[contenthash:8].js'
|
||||
: '[name].js',
|
||||
publicPath: baseUrl,
|
||||
publicPath: isServer ? baseUrl : 'auto',
|
||||
hashFunction: 'xxhash64',
|
||||
},
|
||||
// Don't throw warning when asset created is over 250kb
|
||||
|
|
Loading…
Add table
Reference in a new issue