Skip to content

Commit

Permalink
refactor: support to use README as the default entry (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni authored and PeachScript committed Dec 4, 2019
1 parent d79a04c commit ce06a7c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ function isValidPath(pathname: string) {
* convert TheComponent to the-component and discard ext
*/
export function filenameToPath(name: string) {
return name.replace( /([a-z])([A-Z])/g, '$1-$2' ).replace(/\.\w+$/, '').toLowerCase();
return name.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\.\w+$/, '').toLowerCase();
}

/**
* check the file is default entry
*/
function isDefaultEntry(name: string) {
return name === 'index' || name === 'readme' || name === 'README';
}

/**
Expand Down Expand Up @@ -55,7 +62,7 @@ function findChildRoutes(absPath: string, parentRoutePath: string = '/'): IRoute
switch (fileParsed.ext) {
case '.md':
routes.push({
path: fileParsed.name === 'index' ? parentPath : routePath,
path: isDefaultEntry(fileParsed.name) ? parentPath : routePath,
component: filePath,
exact: true,
meta,
Expand Down

0 comments on commit ce06a7c

Please sign in to comment.