|
|
@ -2,6 +2,7 @@ const path = require('path'); |
|
|
|
const glob = require('glob'); |
|
|
|
const glob = require('glob'); |
|
|
|
const fs = require('fs'); |
|
|
|
const fs = require('fs'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const roadmaps = require('../storage/roadmaps.json'); |
|
|
|
const guides = require('../storage/guides.json'); |
|
|
|
const guides = require('../storage/guides.json'); |
|
|
|
|
|
|
|
|
|
|
|
const PAGES_PATH = path.join(__dirname, '../pages'); |
|
|
|
const PAGES_PATH = path.join(__dirname, '../pages'); |
|
|
@ -56,29 +57,29 @@ const getGuideRoutes = () => { |
|
|
|
* @returns {*} |
|
|
|
* @returns {*} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const getRoadmapRoutes = () => { |
|
|
|
const getRoadmapRoutes = () => { |
|
|
|
const roadmaps = fs.readdirSync(ROADMAPS_PATH); |
|
|
|
return roadmaps.reduce((roadmapRoutes, roadmap) => { |
|
|
|
return roadmaps.reduce((roadmapRoutes, dirName) => { |
|
|
|
const pages = Object.values(roadmap.sidebar || {}) |
|
|
|
const roadmapUrl = `/${dirName}`; |
|
|
|
.reduce((acc, menuPages) => { |
|
|
|
const roadmapDir = path.join(ROADMAPS_PATH, dirName); |
|
|
|
return [ |
|
|
|
const pageFilePaths = glob.sync(`${roadmapDir}/**/*.md`); |
|
|
|
...acc, |
|
|
|
|
|
|
|
...menuPages |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
...roadmapRoutes, |
|
|
|
...roadmapRoutes, |
|
|
|
// Default roadmap path i.e. `{ '/frontend': { page: '/[roadmap]', query: 'frontend' }`
|
|
|
|
// Default roadmap path i.e. `{ '/frontend': { page: '/[roadmap]', query: 'frontend' }`
|
|
|
|
[roadmapUrl]: { |
|
|
|
[roadmap.url]: { |
|
|
|
page: '/[roadmap]', |
|
|
|
page: '/[roadmap]', |
|
|
|
query: dirName, |
|
|
|
query: roadmap.url.replace(/\/+/, ''), |
|
|
|
}, |
|
|
|
}, |
|
|
|
// Routes for all the pages inside this directory
|
|
|
|
// Routes for all the pages inside this directory
|
|
|
|
...pageFilePaths.reduce((pageRoutes, pageFilePath) => { |
|
|
|
...pages.reduce((pageRoutes, page) => { |
|
|
|
const pageFileName = path.basename(pageFilePath, '.md'); |
|
|
|
|
|
|
|
const pageSlug = pageFileName.replace(/^\d+-/, '').toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
...pageRoutes, |
|
|
|
...pageRoutes, |
|
|
|
[`${roadmapUrl}/${pageSlug}`]: { |
|
|
|
[page.url]: { |
|
|
|
page: '/[roadmap]/[page]', |
|
|
|
page: '/[roadmap]/[page]', |
|
|
|
query: `${roadmapUrl}/${pageSlug}` |
|
|
|
query: page.url.replace(/^\//, '') |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, {}) |
|
|
|
}, {}) |
|
|
|