@@ -3,17 +3,15 @@ import fs from 'fs';
33// This file is used to generate the navigation for the site. It is used in the _includes/header.html file.
44// This file will look through the pages directory and generate a list of links based on the front matter of each page.
55// If the front matter includes draft: true, the page will not be included in the navigation.
6- const getNavigation = ( ) =>
7- {
6+ const getNavigation = ( ) => {
87 const navigation = [ ] ;
98 const pagesDirectory = 'pages' ;
109
1110 // loop through the pages directory for any other directories (section titles)
1211 const subdirectories = fs . readdirSync ( pagesDirectory , { withFileTypes : true } )
13- . filter ( dirent => dirent . isDirectory ( ) ) ;
12+ . filter ( dirent => dirent . isDirectory ( ) ) ;
1413
15- subdirectories . forEach ( subdirectory =>
16- {
14+ subdirectories . forEach ( subdirectory => {
1715 const humanReadable = subdirectory . name . replace ( / - / g, ' ' ) . replace ( / \b \w / g, l => l . toUpperCase ( ) ) ;
1816
1917 const section = {
@@ -23,17 +21,16 @@ const getNavigation = () =>
2321
2422 // loop through the files in each directory
2523 const files = fs . readdirSync ( `${ pagesDirectory } /${ subdirectory . name } ` , { withFileTypes : true } )
26- . filter ( dirent => dirent . isFile ( ) ) ;
24+ . filter ( dirent => dirent . isFile ( ) ) ;
2725
28- files . forEach ( file =>
29- {
26+ files . forEach ( file => {
3027 const page = fs . readFileSync ( `${ pagesDirectory } /${ subdirectory . name } /${ file . name } ` , 'utf8' ) ;
3128 const frontMatter = page . split ( '---' ) [ 1 ] ;
32- const draft = frontMatter . includes ( 'draft: true' ) ;
29+ const draft = frontMatter ? frontMatter . includes ( 'draft: true' ) : false ;
3330 // title should be humanized filename
3431 const title = file . name . replace ( / - / g, ' ' )
35- . replace ( '.md' , '' )
36- . replace ( / \b \w / g, l => l . toUpperCase ( ) ) ;
32+ . replace ( '.md' , '' )
33+ . replace ( / \b \w / g, l => l . toUpperCase ( ) ) ;
3734
3835 let url = `/${ subdirectory . name } /${ file . name . replace ( '.md' , '' ) } ` ;
3936 // if filename is the same as the directory name, remove the filename from the url
@@ -45,9 +42,9 @@ const getNavigation = () =>
4542 if ( ! draft )
4643 {
4744 section . items . push ( {
48- 'name' : title ,
49- 'url' : url
50- } ) ;
45+ 'name' : title ,
46+ 'url' : url
47+ } ) ;
5148 }
5249 } ) ;
5350
0 commit comments