Skip to content

Commit

Permalink
fix: Repeat generation and hump naming (#164)
Browse files Browse the repository at this point in the history
* fix: Repeat generation and hump naming

* style: Remove useless code
  • Loading branch information
sy-records authored Feb 9, 2022
1 parent b7e26bd commit 238326e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ' ')
}

0 comments on commit 238326e

Please sign in to comment.