computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
5 years ago
|
const path = require('path');
|
||
|
const glob = require('glob');
|
||
|
|
||
5 years ago
|
const guides = require('../storage/guides.json');
|
||
|
const roadmaps = require('../storage/roadmaps');
|
||
5 years ago
|
|
||
5 years ago
|
const PAGES_PATH = path.join(__dirname, '../pages');
|
||
5 years ago
|
|
||
|
/**
|
||
|
* Generate the page routes from the page files inside `/pages`
|
||
|
* directory. Gives the format understood by next
|
||
|
* {
|
||
|
* '/slug': { page: '/path/to-file' }
|
||
|
* }
|
||
|
*/
|
||
|
const getPageRoutes = () => {
|
||
|
const files = glob.sync(`${PAGES_PATH}/**/*.js`, {
|
||
|
ignore: [
|
||
|
'**/_*.js', // private non-page files e.g. _document.js
|
||
|
'**/[[]*[]].js', // Ignore dynamic pages i.e. `page/[something].js` files
|
||
|
'**/[[]*[]]/*.js', // Ignore files inside dynamic pages i.e. `[something]/abc.js`
|
||
|
]
|
||
|
});
|
||
|
|
||
|
const pageRoutes = {};
|
||
|
files.forEach(file => {
|
||
|
const pageName = file.replace(PAGES_PATH, '').replace('.js', '');
|
||
|
const pagePath = pageName.replace('/index', '') || '/';
|
||
|
|
||
|
pageRoutes[pagePath] = { page: `${pageName}` }
|
||
|
});
|
||
|
|
||
|
return pageRoutes;
|
||
|
};
|
||
|
|
||
5 years ago
|
/**
|
||
|
* Generates routes for guide pages
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
const getGuideRoutes = () => {
|
||
|
return guides.reduce((acc, guide) => {
|
||
|
const [, , slug] = guide.url.split('/');
|
||
|
return {
|
||
|
...acc,
|
||
|
[guide.url]: {
|
||
|
page: '/guides/[guide]',
|
||
|
query: slug,
|
||
|
}
|
||
|
};
|
||
|
}, {});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Generates routes for each of the roadmap and it's respective versions
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
const getRoadmapRoutes = () => {
|
||
|
return roadmaps.reduce((roadmapRoutes, roadmap) => {
|
||
|
const [, slug] = roadmap.url.split('/');
|
||
|
|
||
|
return {
|
||
|
...roadmapRoutes,
|
||
|
// Default roadmap path i.e. `{ '/frontend': { page: '/[roadmap]/index', query: 'frontend' }`
|
||
|
[roadmap.url]: {
|
||
5 years ago
|
page: '/[roadmap]',
|
||
5 years ago
|
query: slug
|
||
|
},
|
||
|
// Route for each of the versions of this roadmap i.e.
|
||
|
// `{ '/frontend/2019': { page: '/[roadmap]/[version]', query: 'frontend/2019' } }`
|
||
5 years ago
|
...((roadmap.versions || []).reduce((versionRoutes, version) => {
|
||
5 years ago
|
return {
|
||
|
...versionRoutes,
|
||
|
[`${roadmap.url}/${version}`]: {
|
||
|
page: '/[roadmap]/[version]',
|
||
|
query: `${slug}/${version}`
|
||
|
}
|
||
|
};
|
||
|
}, {})),
|
||
|
};
|
||
|
}, {});
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
getPageRoutes,
|
||
|
getGuideRoutes,
|
||
|
getRoadmapRoutes,
|
||
|
};
|