Files
e-tib.com/scripts/fix-content.ts
Marc Mintel d14122005d Initial commit: E-TIB production hardening & E2E foundation
Former-commit-id: ef04fca3d76375630c05aac117bf586953f3b657
2026-04-28 19:11:38 +02:00

258 lines
11 KiB
TypeScript

import { getPayload } from 'payload';
import configPromise from '../payload.config';
const fixContent = async () => {
const payload = await getPayload({ config: configPromise });
payload.logger.info('Running complete content alignment script...');
const services = [
{ title: 'Kabelbau', enTitle: 'Cable Construction', description: 'Wir verlegen Kabel für sämtliche Spannungsebenen und übernehmen den kompletten Trassen- und Rohrleitungsbau.', tag: 'Tiefbau', size: 'large' },
{ title: 'Kabelpflugarbeiten', enTitle: 'Cable Plowing', description: 'Umweltschonendes und extrem effizientes Einpflügen von Kabeln und Rohren auf langen Strecken.', tag: 'Spezialmaschinen', size: 'medium' },
{ title: 'Horizontalspülbohrungen', enTitle: 'Directional Drilling', description: 'Grabenlose Leitungsverlegung unter Straßen, Flüssen und Bauwerken hindurch.', tag: 'Bohrtechnik', size: 'small' },
{ title: 'Elektromontagen bis 110 kV', enTitle: 'Electrical Installations', description: 'Installation, Montage und Wartung von Mittel- und Hochspannungsanlagen.', tag: 'Montage', size: 'medium' },
{ title: 'Glasfaser-Kabelmontagen', enTitle: 'Fiber Optic Montage', description: 'Spleißen, Messen und Einblasen von LWL-Kabeln für den modernen Breitbandausbau.', tag: 'Telekommunikation', size: 'small' },
{ title: 'Wartung & Störungsdienst', enTitle: 'Maintenance & Emergency', description: '24/7 Bereitschaft für schnelle Fehlerortung und Reparatur an Kabelanlagen.', tag: 'Service', size: 'accent' },
{ title: 'Genehmigungs- und Ausführungsplanung', enTitle: 'Planning & Permits', description: 'Einholen von Wegerechten und Erstellung baureifer Planungsunterlagen.', tag: 'Planung', size: 'small' },
{ title: 'Komplexe Querung', enTitle: 'Complex Crossings', description: 'Spezialtiefbau für die Unterquerung kritischer Infrastruktur (Bahn, Autobahn, Gewässer).', tag: 'Spezialtiefbau', size: 'large' },
{ title: 'Elektro- und Netzanschlussplanung', enTitle: 'Grid Connection Planning', description: 'Berechnung, Projektierung und Auslegung von Netzanschlüssen.', tag: 'Planung', size: 'medium' },
{ title: 'Vermessung & Dokumentation', enTitle: 'Surveying & Documentation', description: 'Digitale Trasseneinmessung (GPS/Tachymeter) und revisionssichere Dokumentation (GIS).', tag: 'Dokumentation', size: 'small' },
];
try {
for (const loc of ['de', 'en']) {
// 1. Home Page Alignment
const { docs: homeDocs } = await payload.find({
collection: 'pages',
where: { slug: { equals: 'home' } },
locale: loc as any,
limit: 1,
});
if (homeDocs.length > 0) {
payload.logger.info(`Aligning Home page content [${loc}]...`);
let content = homeDocs[0].content as any;
const children = content?.root?.children || [];
// Ensure Hero is correct
const heroIndex = children.findIndex((c: any) => c.fields?.blockType === 'heroVideo');
if (heroIndex >= 0) {
children[heroIndex].fields.title = loc === 'de' ? 'DIE EXPERTEN FÜR KABELTIEFBAU' : 'THE EXPERTS FOR CABLE CONSTRUCTION';
children[heroIndex].fields.subtitle = loc === 'de' ? 'Wir helfen beim Ausbau der Energiekabelnetze für eine grüne Zukunft.' : 'We help expanding the energy cable networks for a green future.';
children[heroIndex].fields.ctaLabel = loc === 'de' ? 'Jetzt anfragen' : 'Request now';
}
// Add/Update Competence Bento on Home
const bentoGridIndex = children.findIndex((c: any) => c.fields?.blockType === 'homeCompetenceBentoGrid');
const bentoBlock = {
type: 'block',
format: '',
version: 2,
fields: {
blockType: 'homeCompetenceBentoGrid',
badge: loc === 'de' ? 'Leistungsspektrum' : 'Service Spectrum',
title: loc === 'de' ? 'Umfassende Lösungen für komplexe Netzwerke' : 'Comprehensive solutions for complex networks',
ctaLabel: loc === 'de' ? 'Alle Kompetenzen ansehen' : 'View all competencies',
ctaHref: loc === 'de' ? '/kompetenzen' : '/en/competencies',
items: services.map(s => ({
title: loc === 'de' ? s.title : s.enTitle,
description: s.description,
tag: s.tag,
size: s.size
})),
},
};
if (bentoGridIndex >= 0) {
children[bentoGridIndex] = bentoBlock;
} else {
children.splice(2, 0, bentoBlock);
}
await payload.update({
collection: 'pages',
id: homeDocs[0].id,
locale: loc as any,
data: {
title: 'Home',
content: { root: { ...content.root, children } }
},
});
}
// 2. Kompetenzen Page
const { docs: compDocs } = await payload.find({
collection: 'pages',
where: { slug: { equals: 'kompetenzen' } },
locale: loc as any,
limit: 1,
});
const compData = {
title: loc === 'de' ? 'Kompetenzen' : 'Competencies',
slug: 'kompetenzen',
_status: 'published',
content: {
root: {
type: 'root',
format: '',
indent: 0,
version: 1,
children: [
{
type: 'block',
format: '',
version: 2,
fields: {
blockType: 'homeCompetenceBentoGrid',
badge: loc === 'de' ? 'Leistungsspektrum' : 'Service Spectrum',
title: loc === 'de' ? 'Unsere Kompetenzen im Überblick' : 'Our Competencies at a glance',
items: services.map(s => ({
title: loc === 'de' ? s.title : s.enTitle,
description: s.description,
tag: s.tag,
size: s.size
})),
},
}
]
}
}
};
if (compDocs.length > 0) {
payload.logger.info(`Updating Kompetenzen page [${loc}]...`);
await payload.update({
collection: 'pages',
id: compDocs[0].id,
locale: loc as any,
data: compData,
});
} else {
payload.logger.info(`Creating Kompetenzen page [${loc}]...`);
await payload.create({
collection: 'pages',
locale: loc as any,
data: compData
});
}
// 3. Über uns (Timeline & Group Tiles)
const { docs: aboutDocs } = await payload.find({
collection: 'pages',
where: { slug: { equals: 'ueber-uns' } },
locale: loc as any,
limit: 1,
});
const aboutData = {
title: loc === 'de' ? 'Über uns' : 'About us',
slug: 'ueber-uns',
_status: 'published',
content: {
root: {
type: 'root',
format: '',
indent: 0,
version: 1,
children: [
{
type: 'block',
format: '',
version: 2,
fields: {
blockType: 'homeSubCompanyTiles',
title: loc === 'de' ? 'Die E-TIB Unternehmensgruppe' : 'The E-TIB Corporate Group',
companies: [
{ title: 'E-TIB GmbH', description: loc === 'de' ? 'Ausführung elektrischer Infrastrukturprojekte.' : 'Execution of electrical infrastructure projects.' },
{ title: 'E-TIB Bohrtechnik GmbH', description: loc === 'de' ? 'Präzise Horizontalbohrungen in allen Bodenklassen.' : 'Precise horizontal directional drilling.' },
{ title: 'E-TIB Ingenieurgesellschaft mbH', description: loc === 'de' ? 'Planung, Projektierung und Dokumentation.' : 'Planning, engineering and documentation.' },
{ title: 'E-TIB Verwaltung GmbH', description: loc === 'de' ? 'Zentrale Dienste, Einkauf und Finanzen.' : 'Central services, purchasing and finance.' },
]
}
},
{
type: 'block',
format: '',
version: 2,
fields: {
blockType: 'companyTimeline',
title: loc === 'de' ? 'Unsere Geschichte' : 'Our History',
items: [
{ year: '2015', title: 'Gründung E-TIB GmbH', description: 'Start der Ausführung von Kabelbauprojekten in Guben.' },
{ year: '2019', title: 'Gründung Ingenieurgesellschaft', description: 'Erweiterung um Planung und Projektierung.' },
{ year: '2025', title: 'Erweiterung Bohrtechnik', description: 'Eigenständige Bohrtechnik-Sparte für Horizontalbohrungen.' },
]
}
}
]
}
}
};
if (aboutDocs.length > 0) {
payload.logger.info(`Updating Über uns page [${loc}]...`);
await payload.update({
collection: 'pages',
id: aboutDocs[0].id,
locale: loc as any,
data: aboutData,
});
} else {
payload.logger.info(`Creating Über uns page [${loc}]...`);
await payload.create({
collection: 'pages',
locale: loc as any,
data: aboutData
});
}
// 4. Impressum
const { docs: impDocs } = await payload.find({
collection: 'pages',
where: { slug: { equals: 'impressum' } },
locale: loc as any,
limit: 1,
});
const impData = {
title: loc === 'de' ? 'Impressum' : 'Imprint',
slug: 'impressum',
_status: 'published',
content: {
root: {
type: 'root',
format: '',
indent: 0,
version: 1,
children: [
{
type: 'paragraph',
children: [{ type: 'text', text: 'E-TIB GmbH\nGewerbestraße 22\n03172 Guben\n\nGeschäftsführung: Danny Joseph\nAmtsgericht Cottbus, HRB 12403 CB\nUSt-ID: DE304799919', version: 1 }]
}
]
}
}
};
if (impDocs.length > 0) {
await payload.update({ collection: 'pages', id: impDocs[0].id, locale: loc as any, data: impData });
} else {
await payload.create({ collection: 'pages', locale: loc as any, data: impData });
}
}
payload.logger.info('✅ Content alignment completed successfully!');
process.exit(0);
} catch (err: any) {
payload.logger.error('❌ Content alignment failed!');
if (err.data) {
payload.logger.error(JSON.stringify(err.data, null, 2));
} else {
payload.logger.error(err.stack || err.message || err);
}
process.exit(1);
}
};
fixContent();