Remove sorting information from best practices content

pull/3356/head
Kamran Ahmed 2 years ago
parent dd7c0ec003
commit e0e6168cfe
  1. 37
      bin/best-practice-content.cjs
  2. 4067
      public/jsons/best-practices/frontend-performance.json
  3. 0
      src/best-practices/frontend-performance/content/analyse-stylesheets-complexity.md
  4. 0
      src/best-practices/frontend-performance/content/analyze-js-for-perf-issues.md
  5. 0
      src/best-practices/frontend-performance/content/avoid-404-files.md
  6. 0
      src/best-practices/frontend-performance/content/avoid-base64-images.md
  7. 0
      src/best-practices/frontend-performance/content/avoid-inline-css.md
  8. 0
      src/best-practices/frontend-performance/content/avoid-multiple-inline-js-snippets.md
  9. 0
      src/best-practices/frontend-performance/content/bundlephobia.md
  10. 0
      src/best-practices/frontend-performance/content/check-dependency-size.md
  11. 0
      src/best-practices/frontend-performance/content/choose-image-format-approprietly.md
  12. 0
      src/best-practices/frontend-performance/content/chrome-dev-tools.md
  13. 0
      src/best-practices/frontend-performance/content/compress-your-images.md
  14. 0
      src/best-practices/frontend-performance/content/concatenate-css-single-file.md
  15. 0
      src/best-practices/frontend-performance/content/cookie-size-less-4096-bytes.md
  16. 0
      src/best-practices/frontend-performance/content/enable-compression.md
  17. 0
      src/best-practices/frontend-performance/content/framework-guides.md
  18. 0
      src/best-practices/frontend-performance/content/inline-critical-css.md
  19. 0
      src/best-practices/frontend-performance/content/keep-cookie-count-below-20.md
  20. 0
      src/best-practices/frontend-performance/content/keep-dependencies-up-to-date.md
  21. 0
      src/best-practices/frontend-performance/content/keep-ttfb-less-1-3s.md
  22. 0
      src/best-practices/frontend-performance/content/keep-web-font-under-300k.md
  23. 0
      src/best-practices/frontend-performance/content/lighthouse.md
  24. 0
      src/best-practices/frontend-performance/content/load-offscreen-images-lazily.md
  25. 0
      src/best-practices/frontend-performance/content/make-css-files-non-blocking.md
  26. 0
      src/best-practices/frontend-performance/content/minify-css.md
  27. 0
      src/best-practices/frontend-performance/content/minify-html.md
  28. 0
      src/best-practices/frontend-performance/content/minify-your-javascript.md
  29. 0
      src/best-practices/frontend-performance/content/minimize-http-requests.md
  30. 0
      src/best-practices/frontend-performance/content/minimize-iframe-count.md
  31. 0
      src/best-practices/frontend-performance/content/page-load-time-below-3s.md
  32. 0
      src/best-practices/frontend-performance/content/page-speed-insights.md
  33. 0
      src/best-practices/frontend-performance/content/page-weight-below-1500.md
  34. 0
      src/best-practices/frontend-performance/content/pre-load-urls-where-possible.md
  35. 0
      src/best-practices/frontend-performance/content/prefer-vector-images.md
  36. 0
      src/best-practices/frontend-performance/content/prevent-flash-text.md
  37. 0
      src/best-practices/frontend-performance/content/recommended-guides.md
  38. 0
      src/best-practices/frontend-performance/content/remove-unused-css.md
  39. 0
      src/best-practices/frontend-performance/content/serve-exact-size-images.md
  40. 0
      src/best-practices/frontend-performance/content/set-width-height-images.md
  41. 0
      src/best-practices/frontend-performance/content/squoosh-ap.md
  42. 0
      src/best-practices/frontend-performance/content/use-cdn.md
  43. 0
      src/best-practices/frontend-performance/content/use-http-cache-headers.md
  44. 0
      src/best-practices/frontend-performance/content/use-https-on-your-website.md
  45. 0
      src/best-practices/frontend-performance/content/use-non-blocking-javascript.md
  46. 0
      src/best-practices/frontend-performance/content/use-preconnect-to-load-fonts.md
  47. 0
      src/best-practices/frontend-performance/content/use-same-protocol.md
  48. 0
      src/best-practices/frontend-performance/content/use-service-workers-for-caching.md
  49. 0
      src/best-practices/frontend-performance/content/use-woff2-font-format.md
  50. 0
      src/best-practices/frontend-performance/content/web-page-test.md

@ -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
Loading…
Cancel
Save