Fix bulletin parsing and display issues

- Improve scripture reference formatting (Ecclesiastes1214: -> Ecclesiastes 12:14)
- Remove end time from Divine Service display (11:00 AM instead of 11:00 AM - 12:15 PM)
- Enhanced parsing logic for better colon-based field detection
- Apply changes to both main bulletin page and individual bulletin pages
This commit is contained in:
Benjamin Slingo 2025-08-28 15:47:43 -04:00
parent 756a755ba6
commit e28c37b8da
2 changed files with 40 additions and 12 deletions

View file

@ -67,8 +67,9 @@ const parseSabbathSchool = (text) => {
let currentKey = '';
lines.forEach(line => {
if (line.includes(':')) {
currentKey = line.replace(':', '').trim();
// Look for lines that end with a colon followed by optional whitespace
if (line.match(/:\s*$/)) {
currentKey = line.replace(/:.*$/, '').trim();
result[currentKey] = '';
} else if (currentKey && line.trim()) {
result[currentKey] = line.trim();
@ -85,8 +86,9 @@ const parseDivineWorship = (text) => {
let currentKey = '';
lines.forEach(line => {
if (line.includes(':')) {
currentKey = line.replace(':', '').trim();
// Look for lines that end with a colon followed by optional whitespace
if (line.match(/:\s*$/)) {
currentKey = line.replace(/:.*$/, '').trim();
result[currentKey] = '';
} else if (currentKey && line.trim()) {
if (result[currentKey]) {
@ -100,6 +102,18 @@ const parseDivineWorship = (text) => {
return result;
};
// Helper function to format scripture references
const formatScriptureReading = (text) => {
if (!text) return null;
// Handle common scripture reference formats
return text
.replace(/([A-Za-z]+)\s*(\d+)(\d{2}):/g, '$1 $2:$3') // Fix Ecclesiastes1214: to Ecclesiastes 12:14
.replace(/([A-Za-z]+)(\d+):/g, '$1 $2:') // Fix other similar patterns
.replace(/\s+/g, ' ') // Normalize whitespace
.trim();
};
const sabbathSchoolInfo = currentBulletin ? parseSabbathSchool(currentBulletin.sabbath_school) : null;
const divineWorshipInfo = currentBulletin ? parseDivineWorship(currentBulletin.divine_worship) : null;
---
@ -169,7 +183,7 @@ const divineWorshipInfo = currentBulletin ? parseDivineWorship(currentBulletin.d
<div class="space-y-3">
<div class="flex items-center space-x-3">
<i data-lucide="clock" class="w-5 h-5 text-primary-500"></i>
<span class="text-gray-600 dark:text-gray-300">11:00 AM - 12:15 PM</span>
<span class="text-gray-600 dark:text-gray-300">11:00 AM</span>
</div>
{divineWorshipInfo && Object.entries(divineWorshipInfo).map(([key, value]) => (
<div class="flex items-start space-x-3">
@ -199,7 +213,7 @@ const divineWorshipInfo = currentBulletin ? parseDivineWorship(currentBulletin.d
<div class="bg-white dark:bg-gray-800 rounded-2xl p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-3">Scripture Reading</h3>
<div class="text-gray-600 dark:text-gray-300 whitespace-pre-line">
{currentBulletin.scripture_reading}
{formatScriptureReading(currentBulletin.scripture_reading) || currentBulletin.scripture_reading}
</div>
</div>
)}

View file

@ -42,8 +42,9 @@ const parseSabbathSchool = (text) => {
let currentKey = '';
lines.forEach(line => {
if (line.includes(':')) {
currentKey = line.replace(':', '').trim();
// Look for lines that end with a colon followed by optional whitespace
if (line.match(/:\s*$/)) {
currentKey = line.replace(/:.*$/, '').trim();
result[currentKey] = '';
} else if (currentKey && line.trim()) {
result[currentKey] = line.trim();
@ -60,8 +61,9 @@ const parseDivineWorship = (text) => {
let currentKey = '';
lines.forEach(line => {
if (line.includes(':')) {
currentKey = line.replace(':', '').trim();
// Look for lines that end with a colon followed by optional whitespace
if (line.match(/:\s*$/)) {
currentKey = line.replace(/:.*$/, '').trim();
result[currentKey] = '';
} else if (currentKey && line.trim()) {
if (result[currentKey]) {
@ -75,6 +77,18 @@ const parseDivineWorship = (text) => {
return result;
};
// Helper function to format scripture references
const formatScriptureReading = (text) => {
if (!text) return null;
// Handle common scripture reference formats
return text
.replace(/([A-Za-z]+)\s*(\d+)(\d{2}):/g, '$1 $2:$3') // Fix Ecclesiastes1214: to Ecclesiastes 12:14
.replace(/([A-Za-z]+)(\d+):/g, '$1 $2:') // Fix other similar patterns
.replace(/\s+/g, ' ') // Normalize whitespace
.trim();
};
const sabbathSchoolInfo = bulletin ? parseSabbathSchool(bulletin.sabbath_school) : null;
const divineWorshipInfo = bulletin ? parseDivineWorship(bulletin.divine_worship) : null;
const displayDate = bulletin ? formatBulletinDate(bulletin.date) : '';
@ -166,7 +180,7 @@ const displayDate = bulletin ? formatBulletinDate(bulletin.date) : '';
<div class="space-y-3">
<div class="flex items-center space-x-3">
<i data-lucide="clock" class="w-5 h-5 text-primary-500"></i>
<span class="text-gray-600 dark:text-gray-300">11:00 AM - 12:15 PM</span>
<span class="text-gray-600 dark:text-gray-300">11:00 AM</span>
</div>
{divineWorshipInfo && Object.entries(divineWorshipInfo).map(([key, value]) => (
<div class="flex items-start space-x-3">
@ -196,7 +210,7 @@ const displayDate = bulletin ? formatBulletinDate(bulletin.date) : '';
<div class="bg-white dark:bg-gray-800 rounded-2xl p-6">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-3">Scripture Reading</h3>
<div class="text-gray-600 dark:text-gray-300 whitespace-pre-line">
{bulletin.scripture_reading}
{formatScriptureReading(bulletin.scripture_reading) || bulletin.scripture_reading}
</div>
</div>
)}