From 21ceabc77c4d6fc0f2a2d122a0089d67f3638f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 3 Apr 2020 17:01:19 -0300 Subject: [PATCH] Improve API docgen sorting --- scripts/gen-nav.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/gen-nav.js b/scripts/gen-nav.js index cb1c99a7c..c796dea6c 100644 --- a/scripts/gen-nav.js +++ b/scripts/gen-nav.js @@ -12,8 +12,21 @@ const files = proc.execFileSync( console.log('.API'); -for (const file of files) { - const doc = file.replace(baseDir, ''); - const title = path.parse(file).name; - console.log(`* xref:${doc}[${startCase(title)}]`); +const links = files.map((file) => { + const doc = file.replace(baseDir, ''); + const title = path.parse(file).name; + + return { + xref: `* xref:${doc}[${startCase(title)}]`, + title, + }; +}); + +// Case-insensitive sort based on titles (so 'token/ERC20' gets sorted as 'erc20') +const sortedLinks = links.sort(function (a, b) { + return a.title.toLowerCase().localeCompare(b.title.toLowerCase()); +}); + +for (const link of sortedLinks) { + console.log(link.xref); }