import { NextPageContext } from "next" ; export interface Context extends NextPageContext { params : { lessonId : string ; chapterId : string ; } ; } import { getCodeAnswerFile , getChapters , getCodeFiles , getLessons , } from "../lib/file" ; import { renderHtml } from "../lib/markdown" ; export const _getStaticProps = ( context ) => { const { params : { lessonId , chapterId } , } = context ; const chapters = getChapters ( parseInt ( lessonId ) ) ; const chapterIndex = chapters . findIndex ( ( l ) => l . id === parseInt ( chapterId ) ) ; const prevChapter = chapters [ chapterIndex - 1 ] || null ; const nextChapter = chapters [ chapterIndex + 1 ] || null ; const codeFiles = getCodeFiles ( lessonId , chapterId ) ; const answerFile = getCodeAnswerFile ( lessonId , chapterId ) ; const { title , fileNameToEdit , body } = renderHtml ( lessonId , chapterId ) ; const currentLessonId = lessonId ; const currentChapterId = chapterId ; return { props : { title , answerFile , content : body , fileNameToEdit , codeFiles , currentLessonId , currentChapterId , prevChapter , nextChapter , currentChapterIndex : chapterIndex , chaptersLength : chapters . length , } , } ; } ; export const _getStaticPaths = ( ) => { const lessons = getLessons ( ) ; let paths = [ ] ; lessons . map ( ( lesson ) => { const chapters = getChapters ( lesson . id ) ; chapters . map ( ( chapter ) => { paths . push ( `/lesson/${ lesson . id }/chapter/${ chapter . id }` ) ; } ) ; } ) ; return { paths : paths , fallback : false , } ; } ;