@@ -3,148 +3,143 @@ import { filterContent, getContentTypeDirectory, getContentTypePath, listContent
33import { ContentType , type Content , type Course , type Author , type Podcast , type Sponsor } from '$lib/types' ;
44
55export const load = ( async ( params ) => {
6- try {
7- const splitPath = params . url . pathname . split ( '/' ) ;
8- const contentType = splitPath . at ( 1 )
9- const path = splitPath . at ( 2 )
10-
11- if ( ! contentType || ! path ) throw error ( 404 ) ;
12- const md = await getContentTypePath < Content & Podcast & Author & Sponsor > ( contentType as ContentType , path ) ;
13- if ( ! md ) throw error ( 404 ) ;
14-
15- const contentItems = await filterContent ( { contentItems : [ md ] } )
16- const content = contentItems ?. at ( 0 ) ;
17- if ( ! content ) throw error ( 404 ) ;
18-
19- // Content is good, fetch surrounding items
20- const authors : Author [ ] = [ ] ;
21- if ( content ?. authors ) {
22- for ( const authorSlug of content . authors ) {
23- const author = await getContentTypePath < Author > ( ContentType . author , authorSlug ) ;
24- if ( author ) authors . push ( author )
25- }
6+ const splitPath = params . url . pathname . split ( '/' ) ;
7+ const contentType = splitPath . at ( 1 )
8+ const path = splitPath . at ( 2 )
9+
10+ if ( ! contentType || ! path ) throw error ( 404 ) ;
11+ const md = await getContentTypePath < Content & Podcast & Author & Sponsor > ( contentType as ContentType , path ) ;
12+ if ( ! md ) throw error ( 404 ) ;
13+
14+ const contentItems = await filterContent ( { contentItems : [ md ] } )
15+ const content = contentItems ?. at ( 0 ) ;
16+ if ( ! content ) throw error ( 404 ) ;
17+
18+ // Content is good, fetch surrounding items
19+ const authors : Author [ ] = [ ] ;
20+ if ( content ?. authors ) {
21+ for ( const authorSlug of content . authors ) {
22+ const author = await getContentTypePath < Author > ( ContentType . author , authorSlug ) ;
23+ if ( author ) authors . push ( author )
2624 }
27- const guests : Author [ ] = [ ] ;
28- if ( content ?. guests ) {
29- for ( const guestSlug of content . guests ) {
30- const guest = await getContentTypePath < Author > ( ContentType . guest , guestSlug ) ;
31- if ( guest ) guests . push ( guest )
32- }
25+ }
26+ const guests : Author [ ] = [ ] ;
27+ if ( content ? .guests ) {
28+ for ( const guestSlug of content . guests ) {
29+ const guest = await getContentTypePath < Author > ( ContentType . guest , guestSlug ) ;
30+ if ( guest ) guests . push ( guest )
3331 }
32+ }
3433
35- const sponsors : Sponsor [ ] = [ ] ;
36- if ( content ?. sponsors ) {
37- for ( const sponsorSlug of content . sponsors ) {
38- const sponsor = await getContentTypePath < Sponsor > ( ContentType . sponsor , sponsorSlug ) ;
39- if ( sponsor ) sponsors . push ( sponsor )
40- }
34+ const sponsors : Sponsor [ ] = [ ] ;
35+ if ( content ?. sponsors ) {
36+ for ( const sponsorSlug of content . sponsors ) {
37+ const sponsor = await getContentTypePath < Sponsor > ( ContentType . sponsor , sponsorSlug ) ;
38+ if ( sponsor ) sponsors . push ( sponsor )
4139 }
40+ }
4241
43- // Static last 3 content
44- const post = ( await listContent < Content > ( {
45- contentItems : await getContentTypeDirectory < Content > ( ContentType . post ) ,
46- limit : 3
47- } ) ) . content
42+ // Static last 3 content
43+ const post = ( await listContent < Content > ( {
44+ contentItems : await getContentTypeDirectory < Content > ( ContentType . post ) ,
45+ limit : 3
46+ } ) ) . content
47+
48+ const course = ( await listContent < Course > ( {
49+ contentItems : await getContentTypeDirectory < Course > ( ContentType . course ) ,
50+ limit : 3
51+ } ) ) . content
52+
53+
54+ const podcast = ( await listContent < Content > ( {
55+ contentItems : await getContentTypeDirectory < Content > ( ContentType . podcast ) ,
56+ limit : 3
57+ } ) ) . content
58+
59+ const baseContent = {
60+ content, // Main Content
61+ authors, // Possibly Empty
62+ guests, // Possibly Empty
63+ sponsors, // Possibly Empty
64+ course, // Top 3
65+ podcast, // Top 3
66+ post, // Top 3
67+ }
4868
49- const course = ( await listContent < Course > ( {
69+ if ( content . type === ContentType . author ) {
70+ const allCourses = ( await listContent < Course > ( {
5071 contentItems : await getContentTypeDirectory < Course > ( ContentType . course ) ,
51- limit : 3
52- } ) ) . content
53-
54-
55- const podcast = ( await listContent < Content > ( {
56- contentItems : await getContentTypeDirectory < Content > ( ContentType . podcast ) ,
57- limit : 3
58- } ) ) . content
59-
60- const baseContent = {
61- content, // Main Content
62- authors, // Possibly Empty
63- guests, // Possibly Empty
64- sponsors, // Possibly Empty
65- course, // Top 3
66- podcast, // Top 3
67- post, // Top 3
68- }
72+ limit : 10000 ,
73+ } ) ) . content ;
6974
70- if ( content . type === ContentType . author ) {
71- const allCourses = ( await listContent < Course > ( {
72- contentItems : await getContentTypeDirectory < Course > ( ContentType . course ) ,
73- limit : 10000 ,
74- } ) ) . content ;
75+ const authorCourses = await listContentByAuthor < Course > ( { authorSlug : content . slug , contentItems : allCourses } )
7576
76- const authorCourses = await listContentByAuthor < Course > ( { authorSlug : content . slug , contentItems : allCourses } )
77-
78- const allPosts = ( await listContent < Content > ( {
79- contentItems : await getContentTypeDirectory < Content > ( ContentType . post ) ,
80- limit : 10000 ,
81- } ) ) . content ;
77+ const allPosts = ( await listContent < Content > ( {
78+ contentItems : await getContentTypeDirectory < Content > ( ContentType . post ) ,
79+ limit : 10000 ,
80+ } ) ) . content ;
8281
83- const authorPosts = await listContentByAuthor < Course > ( { authorSlug : content . slug , contentItems : allPosts } )
82+ const authorPosts = await listContentByAuthor < Course > ( { authorSlug : content . slug , contentItems : allPosts } )
8483
8584
86- return {
87- ...baseContent ,
85+ return {
86+ ...baseContent ,
8887
89- // Author Specific
90- authorCourses,
91- authorPosts
92- }
88+ // Author Specific
89+ authorCourses,
90+ authorPosts
9391 }
92+ }
9493
95- if ( content . type === ContentType . guest ) {
96- const allPodcasts = ( await listContent < Podcast > ( {
97- contentItems : await getContentTypeDirectory < Podcast > ( ContentType . podcast ) ,
98- limit : 10000 ,
99- } ) ) . content ;
94+ if ( content . type === ContentType . guest ) {
95+ const allPodcasts = ( await listContent < Podcast > ( {
96+ contentItems : await getContentTypeDirectory < Podcast > ( ContentType . podcast ) ,
97+ limit : 10000 ,
98+ } ) ) . content ;
10099
101- const guestPodcasts = await listContentByGuest ( { slug : content . slug , podcastItems : allPodcasts } )
100+ const guestPodcasts = await listContentByGuest ( { slug : content . slug , podcastItems : allPodcasts } )
102101
103- return {
104- ...baseContent ,
102+ return {
103+ ...baseContent ,
105104
106- // Guest Specific
107- guestPodcasts
108- }
105+ // Guest Specific
106+ guestPodcasts
109107 }
108+ }
110109
111- if ( content . type === ContentType . sponsor ) {
112- const allCourses = ( await listContent < Course > ( {
113- contentItems : await getContentTypeDirectory < Course > ( ContentType . course ) ,
114- limit : 10000 ,
115- } ) ) . content ;
110+ if ( content . type === ContentType . sponsor ) {
111+ const allCourses = ( await listContent < Course > ( {
112+ contentItems : await getContentTypeDirectory < Course > ( ContentType . course ) ,
113+ limit : 10000 ,
114+ } ) ) . content ;
116115
117- const sponsorCourses = await listContentBySponsor < Course > ( { sponsorSlug : content . slug , contentItems : allCourses } )
116+ const sponsorCourses = await listContentBySponsor < Course > ( { sponsorSlug : content . slug , contentItems : allCourses } )
118117
119- const allPosts = ( await listContent < Content > ( {
120- contentItems : await getContentTypeDirectory < Content > ( ContentType . post ) ,
121- limit : 10000 ,
122- } ) ) . content ;
118+ const allPosts = ( await listContent < Content > ( {
119+ contentItems : await getContentTypeDirectory < Content > ( ContentType . post ) ,
120+ limit : 10000 ,
121+ } ) ) . content ;
123122
124- const sponsorPosts = await listContentBySponsor < Course > ( { sponsorSlug : content . slug , contentItems : allPosts } )
123+ const sponsorPosts = await listContentBySponsor < Course > ( { sponsorSlug : content . slug , contentItems : allPosts } )
125124
126- const allPodcasts = ( await listContent < Podcast > ( {
127- contentItems : await getContentTypeDirectory < Podcast > ( ContentType . podcast ) ,
128- limit : 10000 ,
129- } ) ) . content ;
125+ const allPodcasts = ( await listContent < Podcast > ( {
126+ contentItems : await getContentTypeDirectory < Podcast > ( ContentType . podcast ) ,
127+ limit : 10000 ,
128+ } ) ) . content ;
130129
131- const sponsorPodcasts = await listContentBySponsor ( { sponsorSlug : content . slug , contentItems : allPodcasts } )
130+ const sponsorPodcasts = await listContentBySponsor ( { sponsorSlug : content . slug , contentItems : allPodcasts } )
132131
133132
134- return {
135- ...baseContent ,
133+ return {
134+ ...baseContent ,
136135
137- // Sponsor Specific
138- sponsorCourses,
139- sponsorPosts,
140- sponsorPodcasts
141- }
136+ // Sponsor Specific
137+ sponsorCourses,
138+ sponsorPosts,
139+ sponsorPodcasts
142140 }
143-
144- return baseContent ;
145- }
146- catch ( e ) {
147- console . error ( e )
148- throw error ( 404 )
149141 }
142+
143+ return baseContent ;
144+
150145} )
0 commit comments