mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-06 09:16:29 +02:00
Remove sorting information from best practices content
This commit is contained in:
@@ -41,7 +41,7 @@ if (fs.existsSync(bestPracticeContentDirPath)) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareDirTree(control, dirTree, dirSortOrders) {
|
function prepareDirTree(control, dirTree) {
|
||||||
// Directories are only created for groups
|
// Directories are only created for groups
|
||||||
if (control.typeID !== '__group__') {
|
if (control.typeID !== '__group__') {
|
||||||
return;
|
return;
|
||||||
@@ -49,18 +49,14 @@ function prepareDirTree(control, dirTree, dirSortOrders) {
|
|||||||
|
|
||||||
// e.g. 104-testing-your-apps:other-options
|
// e.g. 104-testing-your-apps:other-options
|
||||||
const controlName = control?.properties?.controlName || '';
|
const controlName = control?.properties?.controlName || '';
|
||||||
// e.g. 104
|
|
||||||
const sortOrder = controlName.match(/^\d+/)?.[0];
|
|
||||||
|
|
||||||
// No directory for a group without control name
|
// No directory for a group without control name
|
||||||
if (!controlName || !sortOrder) {
|
if (!controlName || controlName.startsWith('check:') || controlName.startsWith('ext_link:')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. testing-your-apps:other-options
|
|
||||||
const controlNameWithoutSortOrder = controlName.replace(/^\d+-/, '');
|
|
||||||
// e.g. ['testing-your-apps', 'other-options']
|
// e.g. ['testing-your-apps', 'other-options']
|
||||||
const dirParts = controlNameWithoutSortOrder.split(':');
|
const dirParts = controlName.split(':');
|
||||||
|
|
||||||
// Nest the dir path in the dirTree
|
// Nest the dir path in the dirTree
|
||||||
let currDirTree = dirTree;
|
let currDirTree = dirTree;
|
||||||
@@ -69,37 +65,33 @@ function prepareDirTree(control, dirTree, dirSortOrders) {
|
|||||||
currDirTree = currDirTree[dirPart];
|
currDirTree = currDirTree[dirPart];
|
||||||
});
|
});
|
||||||
|
|
||||||
dirSortOrders[controlNameWithoutSortOrder] = Number(sortOrder);
|
|
||||||
|
|
||||||
const childrenControls = control.children.controls.control;
|
const childrenControls = control.children.controls.control;
|
||||||
// No more children
|
// No more children
|
||||||
if (childrenControls.length) {
|
if (childrenControls.length) {
|
||||||
childrenControls.forEach((childControl) => {
|
childrenControls.forEach((childControl) => {
|
||||||
prepareDirTree(childControl, dirTree, dirSortOrders);
|
prepareDirTree(childControl, dirTree);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { dirTree, dirSortOrders };
|
return { dirTree };
|
||||||
}
|
}
|
||||||
|
|
||||||
const bestPractice = require(path.join(__dirname, `../public/jsons/best-practices/${bestPracticeId}`));
|
const bestPractice = require(path.join(__dirname, `../public/jsons/best-practices/${bestPracticeId}`));
|
||||||
const controls = bestPractice.mockup.controls.control;
|
const controls = bestPractice.mockup.controls.control;
|
||||||
|
|
||||||
// Prepare the dir tree that we will be creating and also calculate the sort orders
|
// Prepare the dir tree that we will be creating
|
||||||
const dirTree = {};
|
const dirTree = {};
|
||||||
const dirSortOrders = {};
|
|
||||||
|
|
||||||
controls.forEach((control) => {
|
controls.forEach((control) => {
|
||||||
prepareDirTree(control, dirTree, dirSortOrders);
|
prepareDirTree(control, dirTree);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parentDir Parent directory in which directory is to be created
|
* @param parentDir Parent directory in which directory is to be created
|
||||||
* @param dirTree Nested dir tree to be created
|
* @param dirTree Nested dir tree to be created
|
||||||
* @param sortOrders Mapping from groupName to sort order
|
|
||||||
* @param filePaths The mapping from groupName to file path
|
* @param filePaths The mapping from groupName to file path
|
||||||
*/
|
*/
|
||||||
function createDirTree(parentDir, dirTree, sortOrders, filePaths = {}) {
|
function createDirTree(parentDir, dirTree, filePaths = {}) {
|
||||||
const childrenDirNames = Object.keys(dirTree);
|
const childrenDirNames = Object.keys(dirTree);
|
||||||
const hasChildren = childrenDirNames.length !== 0;
|
const hasChildren = childrenDirNames.length !== 0;
|
||||||
|
|
||||||
@@ -107,7 +99,6 @@ function createDirTree(parentDir, dirTree, sortOrders, filePaths = {}) {
|
|||||||
const groupName = parentDir
|
const groupName = parentDir
|
||||||
.replace(bestPracticeContentDirPath, '') // Remove base dir path
|
.replace(bestPracticeContentDirPath, '') // Remove base dir path
|
||||||
.replace(/(^\/)|(\/$)/g, '') // Remove trailing slashes
|
.replace(/(^\/)|(\/$)/g, '') // Remove trailing slashes
|
||||||
.replace(/(^\d+?-)/g, '') // Remove sorting information
|
|
||||||
.replaceAll('/', ':') // Replace slashes with `:`
|
.replaceAll('/', ':') // Replace slashes with `:`
|
||||||
.replace(/:\d+-/, ':');
|
.replace(/:\d+-/, ':');
|
||||||
|
|
||||||
@@ -117,15 +108,6 @@ function createDirTree(parentDir, dirTree, sortOrders, filePaths = {}) {
|
|||||||
?.replaceAll('-', ' ')
|
?.replaceAll('-', ' ')
|
||||||
.replace(/^\w/, ($0) => $0.toUpperCase());
|
.replace(/^\w/, ($0) => $0.toUpperCase());
|
||||||
|
|
||||||
const sortOrder = sortOrders[groupName] || '';
|
|
||||||
|
|
||||||
// Attach sorting information to dirname
|
|
||||||
// e.g. /best-practices/frontend-performance/content/internet
|
|
||||||
// ———> /best-practices/frontend-performance/content/103-internet
|
|
||||||
if (sortOrder) {
|
|
||||||
parentDir = parentDir.replace(/(.+?)([^\/]+)?$/, `$1${sortOrder}-$2`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no children, create a file for this under the parent directory
|
// If no children, create a file for this under the parent directory
|
||||||
if (!hasChildren) {
|
if (!hasChildren) {
|
||||||
let fileName = `${parentDir}.md`;
|
let fileName = `${parentDir}.md`;
|
||||||
@@ -150,7 +132,6 @@ function createDirTree(parentDir, dirTree, sortOrders, filePaths = {}) {
|
|||||||
createDirTree(
|
createDirTree(
|
||||||
path.join(parentDir, dirName),
|
path.join(parentDir, dirName),
|
||||||
dirTree[dirName],
|
dirTree[dirName],
|
||||||
dirSortOrders,
|
|
||||||
filePaths
|
filePaths
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -159,5 +140,5 @@ function createDirTree(parentDir, dirTree, sortOrders, filePaths = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create directories and get back the paths for created directories
|
// Create directories and get back the paths for created directories
|
||||||
createDirTree(bestPracticeContentDirPath, dirTree, dirSortOrders);
|
createDirTree(bestPracticeContentDirPath, dirTree);
|
||||||
console.log('Created best practice content directory structure');
|
console.log('Created best practice content directory structure');
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user