diff --git a/scripts/build.js b/scripts/build.js index f43fad83f..440ff76f4 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -121,21 +121,7 @@ console.log(tagDbData); // Create the output for the README file try { - const tags = [ - ...new Set( - Object.entries(tagDbData) - .map(t => t[1][0]) - .filter(v => v) - .sort( - (a, b) => - util.capitalize(a, true) === 'Uncategorized' - ? 1 - : util.capitalize(b, true) === 'Uncategorized' - ? -1 - : a.localeCompare(b) - ) - ) - ]; + const tags = util.prepTaggedData(tagDbData); // Add the start static part output += `${startPart}\n`; diff --git a/scripts/util.js b/scripts/util.js index d43a42694..191b1f48c 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -140,6 +140,16 @@ const getTextualContent = str => { } return results[1]; }; +const prepTaggedData = tagDbData => [...new Set(Object.entries(tagDbData).map(t => t[1][0]))] + .filter(v => v) + .sort( + (a, b) => + capitalize(a, true) === 'Uncategorized' + ? 1 + : capitalize(b, true) === 'Uncategorized' + ? -1 + : a.localeCompare(b) + ); module.exports = { getMarkDownAnchor, getFilesInDir, @@ -153,5 +163,6 @@ module.exports = { shuffle, getCodeBlocks, getTextualContent, - isNotTravisCronOrAPI + isNotTravisCronOrAPI, + prepTaggedData }; diff --git a/scripts/web.js b/scripts/web.js index 372a446d4..c66aeb53e 100644 --- a/scripts/web.js +++ b/scripts/web.js @@ -158,16 +158,7 @@ tagDbData = util.readTags(); // Create the output for individual category pages try { - let taggedData = [...new Set(Object.entries(tagDbData).map(t => t[1][0]))] - .filter(v => v) - .sort( - (a, b) => - util.capitalize(a, true) === 'Uncategorized' - ? 1 - : util.capitalize(b, true) === 'Uncategorized' - ? -1 - : a.localeCompare(b) - ); + let taggedData = util.prepTaggedData(tagDbData); // Add the start static part output += `${startPart}${'\n'}`; // Loop over tags and snippets to create the table of contents