11import { URL_STATIC_API } from '$lib/constants' ;
22import { generateEntries } from '$lib/functions/generateEntries' ;
3+ import { fetchWitnessVerse , fetchFassungVerse } from '$lib/functions/fetchTeiData' ;
34import { metadata } from '$lib/data/metadata' ;
45import sigilFromHandle from '$lib/functions/sigilFromHandle' ;
56import { verses } from '$lib/data/verses' ;
@@ -92,15 +93,18 @@ export async function load({ fetch, params }) {
9293
9394 const nextVerse = index < filteredVerses . length - 1 ? filteredVerses [ index + 1 ] : null ;
9495
95- /** Helper: fetch and consume the body immediately so no Response body is left unread */
96- const fetchJson = ( /** @type {string } */ url ) => fetch ( url ) . then ( ( r ) => ( r . ok ? r . json ( ) : null ) ) ;
96+ /**
97+ * Call the TEI Publisher directly (bypasses internal +server.js endpoints
98+ * to avoid SvelteKit prerenderer "Body has already been read" conflict).
99+ * The data endpoints still exist and prerender for client-side use.
100+ */
97101
98102 // Fetch the textzeugen
99103 const hasSuffix = verseparts [ 1 ] ; // check if there is a suffix in the URL
100104 await Promise . all (
101105 [ ...( await metadata ) . codices , ...( await metadata ) . fragments ] . map (
102106 async ( /** @type {{ handle: string | number; } } */ element ) => {
103- const handlePath = encodeURIComponent ( String ( element . handle ) ) ;
107+ const handle = String ( element . handle ) ;
104108 if ( hasSuffix ) {
105109 const versesToFetch = ( await verses ) . filter (
106110 ( v ) =>
@@ -110,9 +114,7 @@ export async function load({ fetch, params }) {
110114 ) ;
111115
112116 publisherData [ element . handle ] = versesToFetch . map ( ( verseObject ) => {
113- return fetchJson (
114- `/einzelverssynopse/data/${ handlePath } /${ thirties } /${ verseObject . verse } `
115- ) ;
117+ return fetchWitnessVerse ( handle , thirties , verseObject . verse ) ;
116118 } ) ;
117119 hasAdditions = true ;
118120 } else {
@@ -130,9 +132,7 @@ export async function load({ fetch, params }) {
130132 }
131133
132134 publisherData [ element . handle ] = versesToFetch . map ( ( verseObject ) => {
133- return fetchJson (
134- `/einzelverssynopse/data/${ handlePath } /${ thirties } /${ verseObject . verse } `
135- ) ;
135+ return fetchWitnessVerse ( handle , thirties , verseObject . verse ) ;
136136 } ) ;
137137 }
138138 }
@@ -143,10 +143,8 @@ export async function load({ fetch, params }) {
143143 if ( ! hasSuffix ) {
144144 ( await metadata ) . hyparchetypes . forEach (
145145 ( /** @type {{ handle: string | number; } } */ element ) => {
146- const handlePath = encodeURIComponent ( String ( element . handle ) ) ;
147- publisherData [ element . handle ] = [
148- fetchJson ( `/einzelverssynopse/data/fassungen/${ handlePath } /${ thirties } /${ verse ?? '01' } ` )
149- ] ;
146+ const handle = String ( element . handle ) ;
147+ publisherData [ element . handle ] = [ fetchFassungVerse ( handle , thirties , verse ?? '01' ) ] ;
150148 }
151149 ) ;
152150 }
0 commit comments