video strani: cel opis in kazalo gredo v HTML brez JavaScripta, VideoObject description je zdaj daljsi opis in ne le teaser

This commit is contained in:
folx bot
2026-08-24 22:07:59 +02:00
parent b77fd4a28b
commit ed8872226b
+13 -1
View File
@@ -131,13 +131,15 @@ export function serveStatic(app: Express) {
const pageUrl = `${canonicalBase}/video/${v.slug}`; const pageUrl = `${canonicalBase}/video/${v.slug}`;
const poster = `${canonicalBase}${v.posterUrl}`; const poster = `${canonicalBase}${v.posterUrl}`;
const desc = (v.teaser || v.shortTitle || v.title).slice(0, 300); const desc = (v.teaser || v.shortTitle || v.title).slice(0, 300);
const longDesc = String(v.description || v.teaser || v.shortTitle)
.replace(/https?:\/\/\S+/g, "").replace(/\s+/g, " ").trim().slice(0, 900);
const mins = Math.floor((v.durationS || 0) / 60), secs = (v.durationS || 0) % 60; const mins = Math.floor((v.durationS || 0) / 60), secs = (v.durationS || 0) % 60;
const embedUrl = v.embedUrl || `https://www.youtube-nocookie.com/embed/${v.ytId}`; const embedUrl = v.embedUrl || `https://www.youtube-nocookie.com/embed/${v.ytId}`;
const videoLd = { const videoLd = {
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "VideoObject", "@type": "VideoObject",
"name": v.shortTitle, "name": v.shortTitle,
"description": desc, "description": longDesc || desc,
"thumbnailUrl": [poster], "thumbnailUrl": [poster],
"uploadDate": v.publishedAt, "uploadDate": v.publishedAt,
"duration": `PT${mins}M${secs}S`, "duration": `PT${mins}M${secs}S`,
@@ -176,6 +178,15 @@ export function serveStatic(app: Express) {
const chapterHtml = (v.chapters || []).length const chapterHtml = (v.chapters || []).length
? `<h2>Kapitel</h2><ul>${v.chapters.map((c: any) => `<li>${escapeHtml(c.t)} &ndash; ${escapeHtml(c.label)}</li>`).join("")}</ul>` ? `<h2>Kapitel</h2><ul>${v.chapters.map((c: any) => `<li>${escapeHtml(c.t)} &ndash; ${escapeHtml(c.label)}</li>`).join("")}</ul>`
: ""; : "";
// Celoten opis gre v SSR, da ga Google prebere brez JavaScripta.
// Prej je bil v HTML samo naslov in teaser (~320 znakov), ostalo je
// izrisal sele React.
const descHtml = String(v.description || "")
.split(/\n{2,}/)
.map((par: string) => par.trim())
.filter((par: string) => par.length > 2 && !/^https?:\/\//.test(par) && !/^[\u2013\u2014-]{4,}$/.test(par))
.map((par: string) => `<p>${escapeHtml(par).replace(/\n/g, "<br />")}</p>`)
.join("");
const ssr = [ const ssr = [
'<article class="ssr-content">', '<article class="ssr-content">',
`<h1>${escapeHtml(v.shortTitle)}</h1>`, `<h1>${escapeHtml(v.shortTitle)}</h1>`,
@@ -183,6 +194,7 @@ export function serveStatic(app: Express) {
`<p><strong>${escapeHtml(desc)}</strong></p>`, `<p><strong>${escapeHtml(desc)}</strong></p>`,
chapterHtml, chapterHtml,
`<p><a href="${escapeHtml(v.youtubeUrl)}" rel="noopener">Das ganze Video auf YouTube ansehen</a></p>`, `<p><a href="${escapeHtml(v.youtubeUrl)}" rel="noopener">Das ganze Video auf YouTube ansehen</a></p>`,
descHtml ? `<h2>Zum Video</h2>${descHtml}` : "",
"</article>", "</article>",
].join("\n"); ].join("\n");
template = template.replace('<div id="root"></div>', () => `<div id="root">${ssr}</div>`); template = template.replace('<div id="root"></div>', () => `<div id="root">${ssr}</div>`);