This commit is contained in:
2025-11-28 00:26:28 +01:00
parent 9508b9cca8
commit 888c6080ce
2 changed files with 63 additions and 3 deletions

View File

@@ -5,4 +5,4 @@
"flag": "🇩🇪", "flag": "🇩🇪",
"enabled": true "enabled": true
} }
} }

View File

@@ -148,6 +148,11 @@ function addKeyToData(array &$data, string $key, ?string $defaultValue = null):
return; return;
} }
// Dynamische Keys mit Variablen wie pages.$pageKey.meta.title ignorieren
if (strpos($key, '$') !== false) {
return;
}
$default = ($defaultValue !== null && $defaultValue !== '') $default = ($defaultValue !== null && $defaultValue !== '')
? $defaultValue ? $defaultValue
: $key; : $key;
@@ -161,7 +166,7 @@ function addKeyToData(array &$data, string $key, ?string $defaultValue = null):
/** /**
* Extrahiert den „aktuellen Inhalt“ eines data-i18n-Elements * Extrahiert den „aktuellen Inhalt“ eines data-i18n-Elements
* ganz grob über Regex: * grob über Regex:
* ... data-i18n="key"> Inhalt </... * ... data-i18n="key"> Inhalt </...
* Ist nur ein Best-Effort; bei komplexeren Strukturen fällt es auf null zurück. * Ist nur ein Best-Effort; bei komplexeren Strukturen fällt es auf null zurück.
*/ */
@@ -235,6 +240,12 @@ function collectKeysFromFile(string $file): array
)) { )) {
foreach ($m2 as $match) { foreach ($m2 as $match) {
$key = trim($match[2]); $key = trim($match[2]);
// Dynamische Keys mit Variablen wie pages.$pageKey.* hier sofort ignorieren
if (strpos($key, '$') !== false) {
continue;
}
$default = isset($match[5]) ? trim($match[5]) : null; $default = isset($match[5]) ? trim($match[5]) : null;
if ($default !== null && $default !== '') { if ($default !== null && $default !== '') {
@@ -257,6 +268,12 @@ function collectKeysFromFile(string $file): array
)) { )) {
foreach ($m3 as $match) { foreach ($m3 as $match) {
$key = trim($match[2]); $key = trim($match[2]);
// Auch hier dynamische Keys mit $ ignorieren
if (strpos($key, '$') !== false) {
continue;
}
$default = isset($match[5]) ? trim($match[5]) : null; $default = isset($match[5]) ? trim($match[5]) : null;
if ($default !== null && $default !== '') { if ($default !== null && $default !== '') {
@@ -336,6 +353,50 @@ foreach ($foundKeys as $key => $defaultText) {
} }
} }
// -------------------------------
// 5b) Metadaten für alle Landingpages ergänzen
// /public/landingpage/{slug}/ → pages.{slug}.meta.{title,description}
// -------------------------------
$landingRoot = $baseDir . '/public/landingpage';
if (is_dir($landingRoot)) {
foreach (new DirectoryIterator($landingRoot) as $entry) {
if ($entry->isDot() || !$entry->isDir()) {
continue;
}
$slug = $entry->getFilename();
// sehr simple Heuristik: Landingpage gilt als "aktiv", wenn irgendeine .php drin liegt
$hasPhp = false;
foreach (new DirectoryIterator($entry->getPathname()) as $file) {
if ($file->isFile() && strtolower($file->getExtension()) === 'php') {
$hasPhp = true;
break;
}
}
if (!$hasPhp) {
continue;
}
$titleKey = "pages.$slug.meta.title";
$descKey = "pages.$slug.meta.description";
if (!dotKeyExists($data, $titleKey)) {
$defaultTitle = '{{primary_domain}} ' . ucfirst($slug);
addDotKey($data, $titleKey, $defaultTitle);
$newKeys[] = $titleKey;
$addedCount++;
}
if (!dotKeyExists($data, $descKey)) {
$defaultDesc = 'Beschreibung für ' . ucfirst($slug) . ' auf {{primary_domain}}';
addDotKey($data, $descKey, $defaultDesc);
$newKeys[] = $descKey;
$addedCount++;
}
}
}
// ------------------------------- // -------------------------------
// 6) de.json zurückschreiben // 6) de.json zurückschreiben
// ------------------------------- // -------------------------------
@@ -373,7 +434,6 @@ if (!empty($newKeys)) {
if ($isCli) { if ($isCli) {
echo $output; echo $output;
} else { } else {
// Header nur setzen, wenn noch nichts gesendet wurde
if (!headers_sent()) { if (!headers_sent()) {
header('Content-Type: text/plain; charset=utf-8'); header('Content-Type: text/plain; charset=utf-8');
} }