release: WRNexusJS 0.3.5
This commit is contained in:
@@ -31,6 +31,12 @@ export interface RenderOptions {
|
||||
extraBody?: string;
|
||||
/** Attributes for the `<html>` element, e.g. ` data-theme="dark"` (trusted). */
|
||||
htmlAttrs?: string;
|
||||
/**
|
||||
* Optional application-authored full document shell. It must contain
|
||||
* `<html>`, `<head>`, and `<body>`. Framework metadata, assets, and scripts
|
||||
* are merged into it instead of wrapping the rendered body again.
|
||||
*/
|
||||
documentTemplate?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,6 +65,25 @@ export function renderDocument(opts: RenderOptions): string {
|
||||
? (opts.htmlAttrs ?? "")
|
||||
: `${opts.htmlAttrs ?? ""} lang="en"`;
|
||||
|
||||
if (opts.documentTemplate) {
|
||||
let document = opts.documentTemplate.trim();
|
||||
if (!/^<!doctype\s+html>/i.test(document)) document = `<!doctype html>\n${document}`;
|
||||
document = document.replace(/<html([^>]*)>/i, (_match, existing: string) => {
|
||||
const language = /(?:^|\s)lang\s*=/.test(`${existing}${opts.htmlAttrs ?? ""}`)
|
||||
? ""
|
||||
: ' lang="en"';
|
||||
return `<html${existing}${opts.htmlAttrs ?? ""}${language}>`;
|
||||
});
|
||||
const headContent = `
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<title>${title}</title>${seoTags}${preloadTags}${extraHead}`;
|
||||
document = document.replace(/<head([^>]*)>/i, `<head$1>${headContent}`);
|
||||
document = document.replace(/<\/body>/i, `${scriptTags}${extraBody}\n </body>`);
|
||||
return `${document}\n`;
|
||||
}
|
||||
|
||||
return `<!doctype html>
|
||||
<html${htmlAttrs}>
|
||||
<head>
|
||||
|
||||
Reference in New Issue
Block a user