feat: regionale SEO-Daten zentralisieren
This commit is contained in:
1 parent
e5b4903492
commit
1131ca5f81
31 files changed
+300
-131
No files matched your search
+37
-9
@@ -27,19 +27,24 @@ const esc = (s) => String(s).replace(/&/g, '&').replace(/"/g, '"').repl
|
||||
const jsonEsc = (s) => String(s).replace(/</g, '\\u003c');
|
||||
const reEsc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
|
||||
function placeNode(place) {
|
||||
if (typeof place === 'string') return { '@type': 'City', name: place };
|
||||
return { '@type': place.type, name: place.name };
|
||||
}
|
||||
|
||||
function personBusinessGraph() {
|
||||
return { '@context': 'https://schema.org', '@graph': [
|
||||
{ '@type': 'Person', name: biz.personName, jobTitle: biz.personJobTitle, url: SITE_URL, email: biz.email, telephone: biz.telephone },
|
||||
{ '@type': 'ProfessionalService', name: biz.name, url: SITE_URL, telephone: biz.telephone, email: biz.email,
|
||||
address: { '@type': 'PostalAddress', addressLocality: biz.addressLocality, addressRegion: biz.addressRegion, addressCountry: biz.addressCountry },
|
||||
areaServed: biz.areaServed.map((n) => ({ '@type': 'City', name: n })), priceRange: biz.priceRange }
|
||||
areaServed: biz.areaServed.map(placeNode), priceRange: biz.priceRange }
|
||||
]};
|
||||
}
|
||||
|
||||
function breadcrumbListGraph(p) {
|
||||
const segs = p.split('/').filter(Boolean);
|
||||
const labels = {
|
||||
portfolio: 'Portfolio', leistungen: 'Leistungen', 'über-mich': 'Über mich', kontakt: 'Kontakt', blog: 'Blog', archiv: 'Archiv',
|
||||
portfolio: 'Portfolio', leistungen: 'Leistungen', sportfotografie: 'Sportfotografie', eventfotografie: 'Eventfotografie', 'über-mich': 'Über mich', kontakt: 'Kontakt', blog: 'Blog', archiv: 'Archiv',
|
||||
'portfolio-fc-st-pauli': 'FC St. Pauli', 'portfolio-hamburger-sv': 'Hamburger SV', 'portfolio-frauen-bundesliga': 'Frauen-Bundesliga',
|
||||
'portfolio-hannover-96': 'Hannover 96', 'portfolio-sv-meppen': 'SV Meppen', 'portfolio-deutschland-u21': 'Deutschland U21',
|
||||
'portfolio-nfv-pokalfinale-2026': 'NFV-Pokalfinale 2026', 'portfolio-yes-con-2026': 'YES!CON 2026',
|
||||
@@ -58,12 +63,16 @@ function breadcrumbListGraph(p) {
|
||||
return { '@context': 'https://schema.org', '@type': 'BreadcrumbList', itemListElement: items };
|
||||
}
|
||||
|
||||
function serviceGraph() {
|
||||
return { '@context': 'https://schema.org', '@type': 'Service', serviceType: biz.serviceType,
|
||||
function serviceGraph(page) {
|
||||
const data = page.service || {};
|
||||
const serviceType = data.serviceType || biz.serviceType;
|
||||
const areas = data.areaServed || biz.areaServed;
|
||||
const services = data.services || biz.services;
|
||||
return { '@context': 'https://schema.org', '@type': 'Service', serviceType,
|
||||
provider: { '@type': 'ProfessionalService', name: biz.name, url: SITE_URL },
|
||||
areaServed: biz.areaServed.map((n) => ({ '@type': 'City', name: n })),
|
||||
hasOfferCatalog: { '@type': 'OfferCatalog', name: biz.serviceType + '-Leistungen',
|
||||
itemListElement: biz.services.map((s) => ({ '@type': 'Offer', itemOffered: { '@type': 'Service', name: s } })) } };
|
||||
areaServed: areas.map(placeNode),
|
||||
hasOfferCatalog: { '@type': 'OfferCatalog', name: serviceType + '-Leistungen',
|
||||
itemListElement: services.map((name) => ({ '@type': 'Offer', itemOffered: { '@type': 'Service', name } })) } };
|
||||
}
|
||||
|
||||
const BEGIN = '<!-- STATIC-SEO: canonical, Open Graph, Twitter, JSON-LD (aus seo-config.js gebacken) -->';
|
||||
@@ -94,7 +103,7 @@ function buildBlock(p) {
|
||||
const s = page.jsonld || [];
|
||||
if (s.includes('person-business')) L.push(`<script type="application/ld+json" id="seo-person-business">${jsonEsc(JSON.stringify(personBusinessGraph()))}</script>`);
|
||||
if (s.includes('breadcrumb')) L.push(`<script type="application/ld+json" id="seo-breadcrumb">${jsonEsc(JSON.stringify(breadcrumbListGraph(p)))}</script>`);
|
||||
if (s.includes('service')) L.push(`<script type="application/ld+json" id="seo-service">${jsonEsc(JSON.stringify(serviceGraph()))}</script>`);
|
||||
if (s.includes('service')) L.push(`<script type="application/ld+json" id="seo-service">${jsonEsc(JSON.stringify(serviceGraph(page)))}</script>`);
|
||||
L.push(END);
|
||||
return '\t' + L.join('\n\t');
|
||||
}
|
||||
@@ -104,6 +113,25 @@ for (const f of readdirSync(PUB).filter((x) => x.endsWith('.html'))) {
|
||||
const fp = path.join(PUB, f);
|
||||
const p = f === 'index.html' ? '/' : '/' + f.replace(/\.html$/, '');
|
||||
let html = readFileSync(fp, 'utf8');
|
||||
const page = cfg.PAGES[p] || {};
|
||||
if (page.title) {
|
||||
if (!/<title>[\s\S]*?<\/title>/i.test(html)) {
|
||||
console.warn('kein <title> in', f);
|
||||
continue;
|
||||
}
|
||||
html = html.replace(
|
||||
/<title>[\s\S]*?<\/title>/i,
|
||||
`<title>${esc(page.title)}</title>`
|
||||
);
|
||||
}
|
||||
if (page.desc) {
|
||||
const descriptionTag = `<meta name="description" content="${esc(page.desc)}">`;
|
||||
if (/<meta\s+name=["']description["'][^>]*>/i.test(html)) {
|
||||
html = html.replace(/<meta\s+name=["']description["'][^>]*>/i, descriptionTag);
|
||||
} else {
|
||||
html = html.replace('</title>', `</title>\n\t${descriptionTag}`);
|
||||
}
|
||||
}
|
||||
const re = new RegExp(reEsc(BEGIN) + '[\\s\\S]*?' + reEsc(END) + '\\n?');
|
||||
html = html.replace(re, '');
|
||||
if (!html.includes('</head>')) { console.warn('kein </head> in', f); continue; }
|
||||
@@ -111,4 +139,4 @@ for (const f of readdirSync(PUB).filter((x) => x.endsWith('.html'))) {
|
||||
writeFileSync(fp, html);
|
||||
n++;
|
||||
}
|
||||
console.log(`Gebacken: ${n} Seiten`);
|
||||
console.log(`Gebacken: ${n} Seiten`);
|
||||
Reference in new issue
Block a user