From 2d7828590b658cb801836cf7f3f1174e28a4ccf2 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 29 Nov 2019 11:23:48 +0400 Subject: [PATCH] Update path-map generation --- scripts/path-map.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/path-map.js b/scripts/path-map.js index 085e4eebb..980c74e37 100644 --- a/scripts/path-map.js +++ b/scripts/path-map.js @@ -2,6 +2,7 @@ const path = require('path'); const glob = require('glob'); const fs = require('fs'); +const roadmaps = require('../storage/roadmaps.json'); const guides = require('../storage/guides.json'); const PAGES_PATH = path.join(__dirname, '../pages'); @@ -56,29 +57,29 @@ const getGuideRoutes = () => { * @returns {*} */ const getRoadmapRoutes = () => { - const roadmaps = fs.readdirSync(ROADMAPS_PATH); - return roadmaps.reduce((roadmapRoutes, dirName) => { - const roadmapUrl = `/${dirName}`; - const roadmapDir = path.join(ROADMAPS_PATH, dirName); - const pageFilePaths = glob.sync(`${roadmapDir}/**/*.md`); + return roadmaps.reduce((roadmapRoutes, roadmap) => { + const pages = Object.values(roadmap.sidebar || {}) + .reduce((acc, menuPages) => { + return [ + ...acc, + ...menuPages + ] + }, []); return { ...roadmapRoutes, // Default roadmap path i.e. `{ '/frontend': { page: '/[roadmap]', query: 'frontend' }` - [roadmapUrl]: { + [roadmap.url]: { page: '/[roadmap]', - query: dirName, + query: roadmap.url.replace(/\/+/, ''), }, // Routes for all the pages inside this directory - ...pageFilePaths.reduce((pageRoutes, pageFilePath) => { - const pageFileName = path.basename(pageFilePath, '.md'); - const pageSlug = pageFileName.replace(/^\d+-/, '').toLowerCase(); - + ...pages.reduce((pageRoutes, page) => { return { ...pageRoutes, - [`${roadmapUrl}/${pageSlug}`]: { + [page.url]: { page: '/[roadmap]/[page]', - query: `${roadmapUrl}/${pageSlug}` + query: page.url.replace(/^\//, '') } }; }, {})