1- import { listContent , parseModules } from '$lib/server/content' ;
2-
3- export const load = ( async ( ) => {
4-
5- const courseModules = import . meta. glob ( [ '../../../content/course/*/*.md' ] ) ;
6- const tutorialModules = import . meta. glob ( [ '../../../content/tutorial/*.md' ] ) ;
7- const podcastModules = import . meta. glob ( [ '../../../content/podcast/*.md' ] ) ;
8- const postModules = import . meta. glob ( [ '../../../content/post/*.md' ] ) ;
9-
10- const courseItems = await parseModules ( courseModules ) ;
11- const tutorialItems = await parseModules ( tutorialModules ) ;
12- const podcastItems = await parseModules ( podcastModules ) ;
13- const postItems = await parseModules ( postModules ) ;
14-
15- return {
16- course : await ( await listContent ( { contentItems : courseItems , limit : 3 } ) ) . content ,
17- tutorial : await ( await listContent ( { contentItems : tutorialItems , limit : 3 } ) ) . content ,
18- podcast : await ( await listContent ( { contentItems : podcastItems , limit : 3 } ) ) . content ,
19- post : await ( await listContent ( { contentItems : postItems , limit : 3 } ) ) . content
20- } ;
21- } ) ;
1+ import { compile } from 'mdsvex' ;
2+ import { readFileSync } from 'fs' ;
3+ import { fileURLToPath } from 'url' ;
4+ import { error } from '@sveltejs/kit' ;
5+ import { ContentType , type Author , type Content , type Podcast , type Sponsor } from '$lib/types' ;
6+ import { getContentBySlug , listContent , parseModules } from '$lib/server/content' ;
7+
8+
9+ export const prerender = true ;
10+
11+ export const load = ( async ( params ) => {
12+ try {
13+ const file = fileURLToPath ( new URL ( `./${ params . url . pathname } /+page.md` , import . meta. url ) ) ;
14+ const md = readFileSync ( file , 'utf8' ) ;
15+ const transformed = await compile ( md ) ;
16+ const content = transformed ?. data ?. fm as Content & Podcast | undefined ;
17+ const start = content ?. start && new Date ( content . start ) ;
18+ console . log ( start )
19+ if ( start && start < new Date ( ) ) {
20+
21+ const courseModules = import . meta. glob ( [ '../../../content/course/*/*.md' ] ) ;
22+ const tutorialModules = import . meta. glob ( [ '../../../content/tutorial/*.md' ] ) ;
23+ const podcastModules = import . meta. glob ( [ '../../../content/podcast/*.md' ] ) ;
24+ const postModules = import . meta. glob ( [ '../../../content/post/*.md' ] ) ;
25+
26+ const courseItems = await parseModules ( courseModules ) ;
27+ const tutorialItems = await parseModules ( tutorialModules ) ;
28+ const podcastItems = await parseModules ( podcastModules ) ;
29+ const postItems = await parseModules ( postModules ) ;
30+
31+ const guestModules = import . meta. glob ( [ '../../../../../content/guest/*.md' ] ) ;
32+ const guestItems = await parseModules ( guestModules ) ;
33+
34+ const guests : Author [ ] = [ ] ;
35+ if ( content ?. guests ?. length ) {
36+ for ( const guestSlug of content . guests ) {
37+ const guest = await getContentBySlug ( { contentItems : guestItems , slug : guestSlug } ) as unknown as Author ;
38+ if ( guest )
39+ guests . push ( guest ) ;
40+ }
41+ }
42+
43+ const authorModules = import . meta. glob ( [ '../../../../../content/author/*.md' ] ) ;
44+ const authorItems = await parseModules ( authorModules ) ;
45+
46+ const authors : Author [ ] = [ ] ;
47+
48+ for ( const authorSlug of [ 'alex-patterson' , 'brittney-postma' ] ) {
49+ const author = await getContentBySlug ( { contentItems : authorItems , slug : authorSlug } ) as unknown as Author ;
50+ if ( author )
51+ authors . push ( author ) ;
52+ }
53+
54+ const sponsorModules = import . meta. glob ( [ '../../../../../content/sponsor/*.md' ] ) ;
55+ const sponsorItems = await parseModules ( sponsorModules ) ;
56+
57+ const sponsors : Sponsor [ ] = [ ] ;
58+ if ( content ?. sponsors ?. length ) {
59+ for ( const sponsorSlug of content . sponsors ) {
60+ const sponsor = await getContentBySlug ( { contentItems : sponsorItems , slug : sponsorSlug } ) as unknown as Sponsor ;
61+ if ( sponsor )
62+ sponsors . push ( sponsor ) ;
63+ }
64+ }
65+
66+ return {
67+ content,
68+ contentType : ContentType . post ,
69+ course : await ( await listContent ( { contentItems : courseItems , limit : 3 } ) ) . content ,
70+ tutorial : await ( await listContent ( { contentItems : tutorialItems , limit : 3 } ) ) . content ,
71+ podcast : await ( await listContent ( { contentItems : podcastItems , limit : 3 } ) ) . content ,
72+ post : await ( await listContent ( { contentItems : postItems , limit : 3 } ) ) . content
73+ } ;
74+
75+ } else {
76+ throw error ( 404 )
77+ }
78+ }
79+ catch ( e ) {
80+ console . error ( e )
81+ throw error ( 404 )
82+ }
83+ } )
0 commit comments