export const isDynamicRoute = ( path ) : boolean => ! ! path ?. split ( '/' ) ?. some ?. ( snippet => snippet . startsWith ( ':' ) ) ; export const removeSuffixHtml = ( path ) : string => path . replace ( '?' , '' ) . replace ( '(' , '' ) . replace ( ')' , '' ) . replace ( /\.(html|htm)/g , '' ) ; const isHtmlPath = ( path ) : boolean => /\.(html|htm)/g . test ( path ) ; export const findJSON = ( baseDir , fileName ) => { const { join } = require ( 'path' ) ; const { existsSync } = require ( 'fs' ) ; const absFilePath = join ( baseDir , fileName ) ; if ( existsSync ( absFilePath ) ) { return absFilePath ; } return '' ; } ; export const fixHtmlSuffix = route => { if ( route . path && route . path !== '/' && ! isHtmlPath ( route . path ) && ! route . redirect ) { route . path = `${ route . path }(.html)?` ; } } ; export const getStaticRoutePaths = ( _ , routes ) => _ . uniq ( routes . reduce ( ( memo , route ) => { if ( route . path && ! route . redirect ) { memo . push ( removeSuffixHtml ( route . path ) ) ; if ( route . routes ) { memo = memo . concat ( getStaticRoutePaths ( _ , route . routes ) ) ; } } return memo ; } , [ ] ) ) ; param path export const routeToFile = ( path ) : string => { const pathArr = path ?. split ( '/' ) ?. map ?. ( p => { const normalPath = removeSuffixHtml ( p ) ; return isDynamicRoute ( normalPath ) ? `[${ normalPath . replace ( /:/g , '' ) }]` : normalPath ; } ) ; const pathname = path . startsWith ( '/' ) ? pathArr . slice ( 1 ) . join ( '/' ) : pathArr . join ( '/' ) ; return pathname ? `${ pathname }.html` : 'index.html' ; } ;