diff --git a/server/routes-seo.js b/server/routes-seo.js index 02022c8..e38aa62 100644 --- a/server/routes-seo.js +++ b/server/routes-seo.js @@ -42,20 +42,21 @@ function generateHTML(route, meta, __dirname) { // Verwende die gebaute index.html (mit korrekten Asset-Pfaden von Vite) let baseHTML = readFileSync(distIndexPath, 'utf-8'); console.log('[SEO] Gebaute HTML geladen, Länge:', baseHTML.length); + console.log('[SEO] Enthält Script-Tags:', baseHTML.includes('.*?<\/title>/, `${meta.title}`); // Ersetze oder füge description hinzu if (baseHTML.includes(']*>/, ``); + baseHTML = baseHTML.replace(/]*>/g, ``); } else { baseHTML = baseHTML.replace('', ` \n`); } // Ersetze oder füge keywords hinzu if (baseHTML.includes(']*>/, ``); + baseHTML = baseHTML.replace(/]*>/g, ``); } else { baseHTML = baseHTML.replace('', ` \n`); } @@ -73,19 +74,29 @@ function generateHTML(route, meta, __dirname) { `; - // Entferne alte OG/Twitter/Canonical Tags falls vorhanden + // Entferne alte OG/Twitter/Canonical Tags falls vorhanden (nur Meta-Tags, keine Script-Tags!) baseHTML = baseHTML.replace(/]*>/g, ''); baseHTML = baseHTML.replace(/]*>/g, ''); - // Füge neue Tags vor ein - baseHTML = baseHTML.replace('', `${ogTags}\n`); + // Füge neue Tags vor ein (aber NACH den Script-Tags!) + // Finde die Position von und füge die Tags davor ein + const headEndIndex = baseHTML.indexOf(''); + if (headEndIndex !== -1) { + baseHTML = baseHTML.substring(0, headEndIndex) + ogTags + '\n' + baseHTML.substring(headEndIndex); + } // Füge robots meta hinzu falls nicht vorhanden if (!baseHTML.includes('', ` \n`); + const headEndIndex2 = baseHTML.indexOf(''); + if (headEndIndex2 !== -1) { + baseHTML = baseHTML.substring(0, headEndIndex2) + ` \n` + baseHTML.substring(headEndIndex2); + } } + console.log('[SEO] HTML nach Manipulation, Länge:', baseHTML.length); + console.log('[SEO] Enthält Script-Tags nach Manipulation:', baseHTML.includes('