@@ -3,6 +3,7 @@ import type { Content, Course } from '$lib/types';
33import { env } from '$env/dynamic/private' ;
44import { fileURLToPath } from 'url' ;
55import { opendirSync } from "fs" ;
6+ import type { SvelteComponentTyped , ComponentType } from 'svelte' ;
67
78const LIMIT = 20 ;
89
@@ -29,45 +30,33 @@ export const getRootPath = (contentType: ContentType, courseDir?: string) => {
2930 return root ;
3031}
3132
32- export const getContentTypeDirectory = async < T > ( contentType : ContentType , courseDir ?: string ) => {
33+ export const getContentTypeDirectory = async < T > ( contentType : ContentType , courseDir ?: string , render = false ) => {
3334 const contentList : T [ ] = [ ] ;
3435 const dirs = opendirSync ( getRootPath ( contentType , courseDir ) ) ;
3536 for await ( const dir of dirs ) {
3637 if ( dir . isFile ( ) ) continue ;
37- const parsed = await parseContentType < T > ( `${ getRootPath ( contentType , courseDir ) } /${ dir . name } /${ suffix } ` ) as T ;
38+ const parsed = await parseContentType < T > ( `${ getRootPath ( contentType , courseDir ) } /${ dir . name } /${ suffix } ` , render ) as T ;
3839 contentList . push ( parsed ) ;
3940 }
4041 return contentList ;
4142}
4243
43- export const getContentTypePath = async < T > ( contentType : ContentType , path : string , courseDir ?: string ) => {
44+ export const getContentTypePath = async < T > ( contentType : ContentType , path : string , courseDir ?: string , render = false ) => {
4445 const root = getRootPath ( contentType , courseDir ) ;
45- return await parseContentType < T > ( `${ root } /${ path } /${ suffix } ` ) as T ;
46+ return await parseContentType < T > ( `${ root } /${ path } /${ suffix } ` , render ) as T ;
4647}
4748
48- export const parseContentType = ( async < T > ( path : string ) => {
49- // If we are in production everything has already been compiled to JavaScript
50- // and we can just read the metadata, otherwise compile and read.
51- // let frontmatter;
52- // let html;
53- // if (prod) {
54- const { metadata } = await import ( path ) ;
49+ export const parseContentType = ( async < T > ( path : string , render = false ) => {
50+ const { metadata, default : page } = await import ( path ) ;
5551 const frontmatter = metadata ;
56- // } else {
57- // console.log('READ PATH', path);
58- // const md = readFileSync(path, 'utf8');
59- // const transformed = await compile(md);
60- // html = transformed?.code;
61- // frontmatter = transformed?.data?.fm as Content & Podcast | undefined;
62- // }
63- // TODO: Add more checks?
6452
53+ // TODO: Add more checks?
6554 if ( ! frontmatter ?. type ) {
6655 console . error ( 'Missing Frontmatter details' , path ) ;
6756 return ;
6857 }
6958
70- const content = {
59+ let content = {
7160 ...frontmatter ,
7261 cover : frontmatter ?. cover ? decodeURI ( frontmatter ?. cover ) : '' ,
7362 type : frontmatter ?. type as ContentType ,
@@ -77,6 +66,13 @@ export const parseContentType = (async <T>(path: string) => {
7766 slug : path . split ( '/' ) . at ( - 2 )
7867 } ;
7968
69+ if ( render ) {
70+ content = {
71+ ...content ,
72+ html : page ?. render ( ) ?. html
73+ }
74+ }
75+
8076 if ( frontmatter . type === ContentType . course ) {
8177 const lesson = ( await listContent < Content > ( {
8278 contentItems : await getContentTypeDirectory < Content > ( ContentType . lesson , frontmatter . slug ) ,
0 commit comments