Refactor buildWorshipTitleFromPlace in worshipController.js: Rename variables for clarity, enhance location normalization, and improve title generation logic to better handle church names and avoid incorrect titles, ensuring more accurate worship service descriptions.
All checks were successful
Deploy miriamgemeinde / deploy (push) Successful in 7s
All checks were successful
Deploy miriamgemeinde / deploy (push) Successful in 7s
This commit is contained in:
@@ -456,21 +456,40 @@ function resolveLeaderFromText(text, leaderMaps) {
|
||||
function buildWorshipTitleFromPlace(placeName, fallback = 'Gottesdienst') {
|
||||
const raw = normalizeText(placeName);
|
||||
if (!raw) return fallback;
|
||||
let church = raw;
|
||||
let location = raw;
|
||||
let churchLabel = 'Evangelischen Kirche';
|
||||
|
||||
// Typische Muster: "Evangelische Kirche Nieder-Eschbach" -> "Nieder-Eschbach"
|
||||
const afterKirche = raw.match(/kirche\s+(.+)$/i);
|
||||
if (afterKirche && afterKirche[1]) {
|
||||
church = normalizeText(afterKirche[1]);
|
||||
location = normalizeText(afterKirche[1]);
|
||||
} else {
|
||||
const parts = raw.split(/\s*(?:,|\/|->|\(|\)|-)\s*/).filter(Boolean);
|
||||
if (parts.length > 0) {
|
||||
church = normalizeText(parts[parts.length - 1]);
|
||||
location = normalizeText(parts[parts.length - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!church) return fallback;
|
||||
return `Gottesdienst in ${church}`;
|
||||
if (!location) return fallback;
|
||||
|
||||
// Wenn nur Ortsteil erkannt wurde, als Kirchenort formulieren.
|
||||
// So vermeiden wir Titel wie "Gemeindehaus ...", auch wenn der EventPlace so heißt.
|
||||
const normalizedLocation = location
|
||||
.replace(/^evangelisch(?:e|es|er)?\s+(?:gemeindehaus|gemeindezentrum)\s*/i, '')
|
||||
.replace(/^evangelisch(?:e|es|er)?\s+kirche\s*/i, '')
|
||||
.replace(/^kirche\s*/i, '')
|
||||
.trim();
|
||||
|
||||
// Ergänzende Kirchennamen erkennen, z. B. "Evangelische Friedenskirche Harheim".
|
||||
const labelMatch = raw.match(/(evangelisch(?:e|es|er)?\s+[a-zäöüß-]*kirche)\b/i);
|
||||
if (labelMatch && labelMatch[1]) {
|
||||
churchLabel = normalizeText(labelMatch[1]);
|
||||
} else if (/\bfriedenskirche\b/i.test(raw)) {
|
||||
churchLabel = 'Evangelischen Friedenskirche';
|
||||
}
|
||||
|
||||
const finalLocation = normalizedLocation || location;
|
||||
return `Gottesdienst in der ${churchLabel} ${finalLocation}`;
|
||||
}
|
||||
|
||||
function resolveEventPlaceIdFromHeader(eventPlaces, headerCell) {
|
||||
|
||||
Reference in New Issue
Block a user