From c670d4ae67bd8d38e9198b5c785b654fbcc37519 Mon Sep 17 00:00:00 2001 From: Chris Hubbard Date: Thu, 5 Dec 2024 16:45:29 -0500 Subject: [PATCH] Start on songs route --- src/routes/songs/[collection]/[id]/+page.js | 29 +++++++++++++++++++ .../songs/[collection]/[id]/+page.svelte | 0 2 files changed, 29 insertions(+) create mode 100644 src/routes/songs/[collection]/[id]/+page.js create mode 100644 src/routes/songs/[collection]/[id]/+page.svelte diff --git a/src/routes/songs/[collection]/[id]/+page.js b/src/routes/songs/[collection]/[id]/+page.js new file mode 100644 index 000000000..ecc09d228 --- /dev/null +++ b/src/routes/songs/[collection]/[id]/+page.js @@ -0,0 +1,29 @@ +import { base } from '$app/paths'; +import config from '$lib/data/config'; + +/** @type {import('./$types').PageLoad} */ +export async function load({ params, fetch }) { + const id = params.id; + const collection = params.collection; + + const bookCollection = config.bookCollections.find((x) => x.id === collection); + const book = bookCollection.books.find((x) => x.id === id); + + let songs; + try { + const response = await fetch(`${base}/collections/${collection}/songs/${id}.json`); + if (!response.ok) { + throw new Error('Failed to fetch songs JSON file'); + } + + songs = await response.json(); + } catch (error) { + console.error('Error fetching songs JSON file', error); + } + + return { + collection, + id, + songs + }; +} diff --git a/src/routes/songs/[collection]/[id]/+page.svelte b/src/routes/songs/[collection]/[id]/+page.svelte new file mode 100644 index 000000000..e69de29bb