@@ -29,31 +29,30 @@ export const getRootPath = (contentType: ContentType, courseDir?: string) => {
2929 return root ;
3030}
3131
32- export const getContentTypeDirectory = async < T > ( contentType : ContentType , withCode = true , courseDir ?: string ) => {
32+ export const getContentTypeDirectory = async < T > ( contentType : ContentType , courseDir ?: string ) => {
3333 const contentList : T [ ] = [ ] ;
3434 const dirs = opendirSync ( getRootPath ( contentType , courseDir ) ) ;
3535 for await ( const dir of dirs ) {
3636 if ( dir . isFile ( ) ) continue ;
37- const parsed = await parseContentType < T > ( `${ getRootPath ( contentType , courseDir ) } /${ dir . name } /${ suffix } ` , withCode ) as T ;
37+ const parsed = await parseContentType < T > ( `${ getRootPath ( contentType , courseDir ) } /${ dir . name } /${ suffix } ` ) as T ;
3838 contentList . push ( parsed ) ;
3939 }
4040 return contentList ;
4141}
4242
43- export const getContentTypePath = async < T > ( contentType : ContentType , path : string , withCode = true , courseDir ?: string ) => {
43+ export const getContentTypePath = async < T > ( contentType : ContentType , path : string , courseDir ?: string ) => {
4444 const root = getRootPath ( contentType , courseDir ) ;
45- return await parseContentType < T > ( `${ root } /${ path } /${ suffix } ` , withCode ) as T ;
45+ return await parseContentType < T > ( `${ root } /${ path } /${ suffix } ` ) as T ;
4646}
4747
48- export const parseContentType = ( async < T > ( path : string , withCode = true ) => {
48+ export const parseContentType = ( async < T > ( path : string ) => {
4949 // If we are in production everything has already been compiled to JavaScript
5050 // and we can just read the metadata, otherwise compile and read.
5151 // let frontmatter;
5252 // let html;
5353 // if (prod) {
54- const { metadata, default : Page } = await import ( path ) ;
54+ const { metadata } = await import ( path ) ;
5555 const frontmatter = metadata ;
56- const html = Page ?. render ( ) ?. html ;
5756 // } else {
5857 // console.log('READ PATH', path);
5958 // const md = readFileSync(path, 'utf8');
@@ -64,15 +63,14 @@ export const parseContentType = (async <T>(path: string, withCode = true) => {
6463 // TODO: Add more checks?
6564
6665 if ( ! frontmatter ?. type ) {
67- console . error ( 'Missing Frontmatter details' ) ;
66+ console . error ( 'Missing Frontmatter details' , path ) ;
6867 return ;
6968 }
7069
7170 const content = {
7271 ...frontmatter ,
7372 cover : frontmatter ?. cover ? decodeURI ( frontmatter ?. cover ) : '' ,
7473 type : frontmatter ?. type as ContentType ,
75- html : withCode ? html : undefined ,
7674 weight : frontmatter ?. weight ? frontmatter ?. weight : 0 ,
7775 published : frontmatter ?. published ? frontmatter ?. published : ContentPublished . draft ,
7876 start : frontmatter ?. start ? new Date ( frontmatter ?. start ) : new Date ( 'Jan 01, 2000' ) ,
@@ -81,7 +79,7 @@ export const parseContentType = (async <T>(path: string, withCode = true) => {
8179
8280 if ( frontmatter . type === ContentType . course ) {
8381 const lesson = ( await listContent < Content > ( {
84- contentItems : await getContentTypeDirectory < Content > ( ContentType . lesson , false , frontmatter . slug ) ,
82+ contentItems : await getContentTypeDirectory < Content > ( ContentType . lesson , frontmatter . slug ) ,
8583 limit : 10000
8684 } ) ) . content
8785 return { ...content , lesson } as T ;
@@ -124,15 +122,15 @@ export const filterContent = async <T extends Content>({
124122 contentItems : T [ ] ;
125123} ) => {
126124 const doc = contentItems
127- . filter (
125+ ? .filter (
128126 preview ?
129127 ( ) => true
130128 :
131- ( c ) => new Date ( c . start ) <= new Date ( ) &&
129+ ( c ) => c ?. start ? new Date ( c . start ) <= new Date ( ) : false &&
132130 c . published === ContentPublished . published
133131 )
134- . sort ( ( a , b ) => new Date ( b . start ) . valueOf ( ) - new Date ( a . start ) . valueOf ( ) )
135- . map ( ( c : Course ) => {
132+ ? .sort ( ( a , b ) => a ?. start && b ?. start && new Date ( b . start ) . valueOf ( ) - new Date ( a . start ) . valueOf ( ) )
133+ ? .map ( ( c : Course ) => {
136134 return {
137135 ...c ,
138136 lesson : c ?. lesson
0 commit comments