From e3fe66abb7642c5d8d8ea618add9899848af7946 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sun, 30 Jan 2022 08:16:14 +0800 Subject: [PATCH 1/2] fix: Repeat generation and hump naming --- lib/commands/generate.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/commands/generate.js b/lib/commands/generate.js index 95943dc..f48457b 100644 --- a/lib/commands/generate.js +++ b/lib/commands/generate.js @@ -40,14 +40,18 @@ function genSidebar(cwdPath, sidebarPath) { let filename = path.basename(pathname, '.md') let splitPath = pathname.split(path.sep) + if (ignoreFiles.indexOf(filename) !== -1) { + return true + } + if (ignoreFiles.indexOf(filename) === -1) { - nodeName = '- [' + filename + '](' + pathname + ')' + os.EOL + 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 +82,9 @@ function getDirFiles(dir, callback) { } }) } + +function toCamelCase(str) { + return str.replace(/\b(\w)/g, function (match, capture) { + return capture.toUpperCase() + }).replace(/-|_/g, ' ') +} From 3b3f1cca0c5d415517aa22c31c3a8f1b94fb2baa Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Sun, 30 Jan 2022 08:24:56 +0800 Subject: [PATCH 2/2] style: Remove useless code --- lib/commands/generate.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/commands/generate.js b/lib/commands/generate.js index f48457b..9326c24 100644 --- a/lib/commands/generate.js +++ b/lib/commands/generate.js @@ -44,9 +44,7 @@ function genSidebar(cwdPath, sidebarPath) { return true } - if (ignoreFiles.indexOf(filename) === -1) { - nodeName = '- [' + toCamelCase(filename) + '](' + pathname + ')' + os.EOL - } + nodeName = '- [' + toCamelCase(filename) + '](' + pathname + ')' + os.EOL if (splitPath.length > 1) { if (splitPath[0] !== lastPath) {