add text content in static html for seo
This commit is contained in:
parent
10e328f2a3
commit
723a0138b6
1 changed files with 16 additions and 1 deletions
|
@ -35,9 +35,24 @@ export async function handle({ event, resolve }) {
|
|||
`;
|
||||
}
|
||||
|
||||
let stringsHTML = stringsToHTML(strings);
|
||||
|
||||
const response = await resolve(event, {
|
||||
transformPageChunk: ({ html }) => html.replace('<head>', head)
|
||||
transformPageChunk: ({ html }) => html.replace('<head>', head).replace('<body data-sveltekit-preload-data="hover">', `<body data-sveltekit-preload-data="hover"><div class="hidden">${stringsHTML}</div>`)
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
function stringsToHTML(dictionary, strings = new Set(), root = true) {
|
||||
Object.values(dictionary).forEach((value) => {
|
||||
if (typeof value === 'object') {
|
||||
stringsToHTML(value, strings, false);
|
||||
} else {
|
||||
strings.add(value);
|
||||
}
|
||||
});
|
||||
if (root) {
|
||||
return Array.from(strings).map((string) => `<p>${string}</p>`).join('');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue