From 6ff98b387ff6b52cf69342cf4a35bf719cdd0449 Mon Sep 17 00:00:00 2001 From: Sebastian Flick Date: Sat, 2 Nov 2024 22:29:03 +0100 Subject: [PATCH] add data route for fassungen (not fully working yet) --- .../fassungen/data/[thirties]/+server.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/routes/fassungen/data/[thirties]/+server.js diff --git a/src/routes/fassungen/data/[thirties]/+server.js b/src/routes/fassungen/data/[thirties]/+server.js new file mode 100644 index 0000000..94e309b --- /dev/null +++ b/src/routes/fassungen/data/[thirties]/+server.js @@ -0,0 +1,28 @@ +import { json } from '@sveltejs/kit'; +import { api, teipb } from '$lib/constants'; + +/** @type {import('./$types').RequestHandler} */ +export async function GET({ params, fetch }) { + const { hyparchetypes } = await fetch(`${api}/json/metadata-nomenclature.json`).then((r) => + r.json() + ); + const teipbData = await hyparchetypes.map(async (h) => { + const r = await fetch( + `${teipb}/parts/syn${params.thirties}.xml/json?&view=single&odd=parzival-verse.odd&xpath=//div[@subtype=%27${h.handle.replace('*', '')}%27]` + ); + if (!r.ok) { + console.log('Failed to fetch tpData', r); + return false; + } + return r.json(); + }); + return json(await teipbData); +} + +/** @type {import('./$types').EntryGenerator} */ +export async function entries() { + const entriesArray = Array.from({ length: 827 }, (_, i) => ({ thirties: i + 1 })); + return entriesArray; +} + +export const prerender = true;