diff --git a/lib/commands/generate.js b/lib/commands/generate.js index 95943dc..9326c24 100644 --- a/lib/commands/generate.js +++ b/lib/commands/generate.js @@ -40,14 +40,16 @@ function genSidebar(cwdPath, sidebarPath) { let filename = path.basename(pathname, '.md') let splitPath = pathname.split(path.sep) - if (ignoreFiles.indexOf(filename) === -1) { - nodeName = '- [' + filename + '](' + pathname + ')' + os.EOL + if (ignoreFiles.indexOf(filename) !== -1) { + return true } + nodeName = '- [' + toCamelCase(filename) + '](' + pathname + ')' + os.EOL + if (splitPath.length > 1) { if (splitPath[0] !== lastPath) { lastPath = splitPath[0] - tree += os.EOL + '- ' + splitPath[0] + os.EOL + tree += os.EOL + '- ' + toCamelCase(splitPath[0]) + os.EOL } tree += ' ' + nodeName @@ -78,3 +80,9 @@ function getDirFiles(dir, callback) { } }) } + +function toCamelCase(str) { + return str.replace(/\b(\w)/g, function (match, capture) { + return capture.toUpperCase() + }).replace(/-|_/g, ' ') +}