Skip to content

Commit 238326e

Browse files
authored
fix: Repeat generation and hump naming (#164)
* fix: Repeat generation and hump naming * style: Remove useless code
1 parent b7e26bd commit 238326e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/commands/generate.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ function genSidebar(cwdPath, sidebarPath) {
4040
let filename = path.basename(pathname, '.md')
4141
let splitPath = pathname.split(path.sep)
4242

43-
if (ignoreFiles.indexOf(filename) === -1) {
44-
nodeName = '- [' + filename + '](' + pathname + ')' + os.EOL
43+
if (ignoreFiles.indexOf(filename) !== -1) {
44+
return true
4545
}
4646

47+
nodeName = '- [' + toCamelCase(filename) + '](' + pathname + ')' + os.EOL
48+
4749
if (splitPath.length > 1) {
4850
if (splitPath[0] !== lastPath) {
4951
lastPath = splitPath[0]
50-
tree += os.EOL + '- ' + splitPath[0] + os.EOL
52+
tree += os.EOL + '- ' + toCamelCase(splitPath[0]) + os.EOL
5153
}
5254

5355
tree += ' ' + nodeName
@@ -78,3 +80,9 @@ function getDirFiles(dir, callback) {
7880
}
7981
})
8082
}
83+
84+
function toCamelCase(str) {
85+
return str.replace(/\b(\w)/g, function (match, capture) {
86+
return capture.toUpperCase()
87+
}).replace(/-|_/g, ' ')
88+
}

0 commit comments

Comments
 (0)