fix: render header after group flush for proper ordering

This commit is contained in:
catarrh committed 2026-08-02 00:38:46 +03:00
1 parent ebfd799723
commit 444d7e592b
1 file changed
+5 -4
+5 -4
View File
@@ -316,13 +316,14 @@ export async function assembleService(
const prayerNodes = await ctx.fetchPrayerNodes(`Services/CommonPrayers/${what}.xml`); const prayerNodes = await ctx.fetchPrayerNodes(`Services/CommonPrayers/${what}.xml`);
if (prayerNodes && prayerNodes.length > 0) { if (prayerNodes && prayerNodes.length > 0) {
header = await ctx.fetchText(`Services/CommonPrayers/${what}.xml.header`) ?? ''; header = await ctx.fetchText(`Services/CommonPrayers/${what}.xml.header`) ?? '';
// Check if any TEXT nodes have their own who field
const hasWhoNodes = prayerNodes.some(n => n.type === 'TEXT' && str((n as Record<string, unknown>).who) !== undefined);
if (hasWhoNodes) {
// Render header before individual who-nodes
const headerHtml = n.header && header const headerHtml = n.header && header
? `<h2 class="text-center text-red font-bold mt-4">${header}</h2>` ? `<h2 class="text-center text-red font-bold mt-4">${header}</h2>`
: ''; : '';
if (headerHtml) html += headerHtml + '\n'; if (headerHtml) html += headerHtml + '\n';
// Check if any TEXT nodes have their own who field
const hasWhoNodes = prayerNodes.some(n => n.type === 'TEXT' && str((n as Record<string, unknown>).who) !== undefined);
if (hasWhoNodes) {
for (const pn of prayerNodes) { for (const pn of prayerNodes) {
if (pn.type !== 'TEXT') continue; if (pn.type !== 'TEXT') continue;
const pnWhoRaw = str((pn as Record<string, unknown>).who); const pnWhoRaw = str((pn as Record<string, unknown>).who);
@@ -357,7 +358,7 @@ export async function assembleService(
.map(n => String(str((n as Record<string, unknown>).value) ?? '').replace(/\n/g, ' ')) .map(n => String(str((n as Record<string, unknown>).value) ?? '').replace(/\n/g, ' '))
.filter(Boolean) .filter(Boolean)
.join('<br>') || ''; .join('<br>') || '';
header = ''; // Prevent double rendering in the fallthrough below // header is preserved for rendering after group flush below
} else { } else {
// No structured nodes — use fetchText // No structured nodes — use fetchText
text = await ctx.fetchText(`Services/CommonPrayers/${what}.xml`) ?? ''; text = await ctx.fetchText(`Services/CommonPrayers/${what}.xml`) ?? '';