SSR: vsebina clanka v HTML za Google/Discover
This commit is contained in:
parent
ef33ad68fa
commit
fda5e2ce62
@ -130,6 +130,17 @@ export function serveStatic(app: Express) {
|
|||||||
|
|
||||||
template = template.replace(/<title>[^<]*<\/title>/, ogTags);
|
template = template.replace(/<title>[^<]*<\/title>/, ogTags);
|
||||||
|
|
||||||
|
// SSR: vgradi vsebino clanka v HTML, da jo Google/Discover vidita brez JS
|
||||||
|
const ssrBlock = [
|
||||||
|
'<article class="ssr-content">',
|
||||||
|
`<h1>${escapeHtml(article.title)}</h1>`,
|
||||||
|
imageUrl ? `<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(article.title)}" style="max-width:100%;height:auto;" />` : "",
|
||||||
|
`<p><strong>${escapeHtml(article.excerpt)}</strong></p>`,
|
||||||
|
article.content || "",
|
||||||
|
"</article>",
|
||||||
|
].join("\n");
|
||||||
|
template = template.replace('<div id="root"></div>', () => `<div id="root">${ssrBlock}</div>`);
|
||||||
|
|
||||||
res.status(200).set({ "Content-Type": "text/html" }).end(template);
|
res.status(200).set({ "Content-Type": "text/html" }).end(template);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user