From 238326e79a8f5dfbaba86e4e197c05655f5945e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Wed, 9 Feb 2022 08:20:56 +0800 Subject: [PATCH] fix: Repeat generation and hump naming (#164) * fix: Repeat generation and hump naming * style: Remove useless code --- lib/commands/generate.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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, ' ') +}