@@ -61,7 +61,7 @@ export async function getLessons() {
6161 for ( let dirFilename of dir ) {
6262 const dirStats = await fs . lstat ( path . join ( lessonsPath , dirFilename ) ) ;
6363
64- if ( dirStats . isFile ( ) ) {
64+ if ( ! dirStats . isDirectory ( ) ) {
6565 continue ;
6666 }
6767
@@ -129,6 +129,10 @@ export async function getLesson(targetDir, targetFile) {
129129
130130 for ( let i = 0 ; i < dir . length ; i ++ ) {
131131 const dirPath = dir [ i ] ;
132+ const dirStats = await fs . lstat ( path . join ( lessonsPath , dirPath ) ) ;
133+ if ( ! dirStats . isDirectory ( ) ) {
134+ continue ;
135+ }
132136 if ( dirPath . endsWith ( targetDir ) ) {
133137 const lessonDir = (
134138 await fs . readdir ( path . join ( lessonsPath , dirPath ) )
@@ -157,15 +161,22 @@ export async function getLesson(targetDir, targetFile) {
157161 nextSlug = `${ targetDir } /${ next . replace ( / \. m d $ / , "" ) } ` ;
158162 } else if ( dir [ i + 1 ] ) {
159163 // has next in next section
160- const nextDir = (
161- await fs . readdir ( path . join ( lessonsPath , dir [ i + 1 ] ) )
162- ) . filter ( ( str ) => str . endsWith ( ".md" ) ) ;
163- const nextDirSlug = slugify ( dir [ i + 1 ] ) . slug ;
164- const nextLessonSlug = slugify ( nextDir [ 0 ] ) . slug . replace (
165- / \. m d $ / ,
166- ""
164+ const nextDirStats = await fs . lstat (
165+ path . join ( lessonsPath , dir [ i + 1 ] )
167166 ) ;
168- nextSlug = `${ nextDirSlug } /${ nextLessonSlug } ` ;
167+ if ( ! nextDirStats . isDirectory ( ) ) {
168+ nextSlug = null ;
169+ } else {
170+ const nextDir = (
171+ await fs . readdir ( path . join ( lessonsPath , dir [ i + 1 ] ) )
172+ ) . filter ( ( str ) => str . endsWith ( ".md" ) ) ;
173+ const nextDirSlug = slugify ( dir [ i + 1 ] ) . slug ;
174+ const nextLessonSlug = slugify ( nextDir [ 0 ] ) . slug . replace (
175+ / \. m d $ / ,
176+ ""
177+ ) ;
178+ nextSlug = `${ nextDirSlug } /${ nextLessonSlug } ` ;
179+ }
169180 } else {
170181 // last section
171182 nextSlug = null ;
@@ -178,14 +189,21 @@ export async function getLesson(targetDir, targetFile) {
178189 prevSlug = `${ targetDir } /${ prev . replace ( / \. m d $ / , "" ) } ` ;
179190 } else if ( dir [ i - 1 ] ) {
180191 // has prev in prev section
181- const prevDir = (
182- await fs . readdir ( path . join ( lessonsPath , dir [ i - 1 ] ) )
183- ) . filter ( ( str ) => str . endsWith ( ".md" ) ) ;
184- const prevDirSlug = slugify ( dir [ i - 1 ] ) . slug ;
185- const prevLessonSlug = slugify (
186- prevDir [ prevDir . length - 1 ]
187- ) . slug . replace ( / \. m d $ / , "" ) ;
188- prevSlug = `${ prevDirSlug } /${ prevLessonSlug } ` ;
192+ const prevDirStats = await fs . lstat (
193+ path . join ( lessonsPath , dir [ i - 1 ] )
194+ ) ;
195+ if ( ! prevDirStats . isDirectory ( ) ) {
196+ prevSlug = null ;
197+ } else {
198+ const prevDir = (
199+ await fs . readdir ( path . join ( lessonsPath , dir [ i - 1 ] ) )
200+ ) . filter ( ( str ) => str . endsWith ( ".md" ) ) ;
201+ const prevDirSlug = slugify ( dir [ i - 1 ] ) . slug ;
202+ const prevLessonSlug = slugify (
203+ prevDir [ prevDir . length - 1 ]
204+ ) . slug . replace ( / \. m d $ / , "" ) ;
205+ prevSlug = `${ prevDirSlug } /${ prevLessonSlug } ` ;
206+ }
189207 } else {
190208 // first section
191209 prevSlug = null ;
0 commit comments