File tree Expand file tree Collapse file tree
src/routes/songs/[collection]/[id] Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { base } from '$app/paths' ;
2+ import config from '$lib/data/config' ;
3+
4+ /** @type {import('./$types').PageLoad } */
5+ export async function load ( { params, fetch } ) {
6+ const id = params . id ;
7+ const collection = params . collection ;
8+
9+ const bookCollection = config . bookCollections . find ( ( x ) => x . id === collection ) ;
10+ const book = bookCollection . books . find ( ( x ) => x . id === id ) ;
11+
12+ let songs ;
13+ try {
14+ const response = await fetch ( `${ base } /collections/${ collection } /songs/${ id } .json` ) ;
15+ if ( ! response . ok ) {
16+ throw new Error ( 'Failed to fetch songs JSON file' ) ;
17+ }
18+
19+ songs = await response . json ( ) ;
20+ } catch ( error ) {
21+ console . error ( 'Error fetching songs JSON file' , error ) ;
22+ }
23+
24+ return {
25+ collection,
26+ id,
27+ songs
28+ } ;
29+ }
You can’t perform that action at this time.
0 commit comments