|
|
@ -1,10 +1,12 @@ |
|
|
|
const path = require('path'); |
|
|
|
const path = require('path'); |
|
|
|
const glob = require('glob'); |
|
|
|
const glob = require('glob'); |
|
|
|
|
|
|
|
const fs = require('fs'); |
|
|
|
|
|
|
|
|
|
|
|
const guides = require('../storage/guides.json'); |
|
|
|
const guides = require('../storage/guides.json'); |
|
|
|
const roadmaps = require('../storage/roadmaps'); |
|
|
|
const roadmaps = require('../storage/roadmaps'); |
|
|
|
|
|
|
|
|
|
|
|
const PAGES_PATH = path.join(__dirname, '../pages'); |
|
|
|
const PAGES_PATH = path.join(__dirname, '../pages'); |
|
|
|
|
|
|
|
const ROADMAPS_PATH = path.join(__dirname, '../storage/roadmaps'); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Generate the page routes from the page files inside `/pages` |
|
|
|
* Generate the page routes from the page files inside `/pages` |
|
|
@ -19,7 +21,7 @@ const getPageRoutes = () => { |
|
|
|
'**/_*.js', // private non-page files e.g. _document.js
|
|
|
|
'**/_*.js', // private non-page files e.g. _document.js
|
|
|
|
'**/[[]*[]].js', // Ignore dynamic pages i.e. `page/[something].js` files
|
|
|
|
'**/[[]*[]].js', // Ignore dynamic pages i.e. `page/[something].js` files
|
|
|
|
'**/[[]*[]]/*.js', // Ignore files inside dynamic pages i.e. `[something]/abc.js`
|
|
|
|
'**/[[]*[]]/*.js', // Ignore files inside dynamic pages i.e. `[something]/abc.js`
|
|
|
|
] |
|
|
|
], |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const pageRoutes = {}; |
|
|
|
const pageRoutes = {}; |
|
|
@ -45,7 +47,7 @@ const getGuideRoutes = () => { |
|
|
|
[guide.url]: { |
|
|
|
[guide.url]: { |
|
|
|
page: '/guides/[guide]', |
|
|
|
page: '/guides/[guide]', |
|
|
|
query: slug, |
|
|
|
query: slug, |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, {}); |
|
|
|
}, {}); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -55,31 +57,38 @@ const getGuideRoutes = () => { |
|
|
|
* @returns {*} |
|
|
|
* @returns {*} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const getRoadmapRoutes = () => { |
|
|
|
const getRoadmapRoutes = () => { |
|
|
|
return roadmaps.reduce((roadmapRoutes, roadmap) => { |
|
|
|
const roadmaps = fs.readdirSync(ROADMAPS_PATH); |
|
|
|
const [, slug] = roadmap.url.split('/'); |
|
|
|
return roadmaps.reduce((roadmapRoutes, dirName) => { |
|
|
|
|
|
|
|
const roadmapUrl = `/${dirName}`; |
|
|
|
|
|
|
|
const roadmapDir = path.join(ROADMAPS_PATH, dirName); |
|
|
|
|
|
|
|
const pageFilePaths = glob.sync(`${roadmapDir}/**/*.md`); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
...roadmapRoutes, |
|
|
|
...roadmapRoutes, |
|
|
|
// Default roadmap path i.e. `{ '/frontend': { page: '/[roadmap]/index', query: 'frontend' }`
|
|
|
|
// Default roadmap path i.e. `{ '/frontend': { page: '/[roadmap]', query: 'frontend' }`
|
|
|
|
[roadmap.url]: { |
|
|
|
[roadmapUrl]: { |
|
|
|
page: '/[roadmap]', |
|
|
|
page: '/[roadmap]', |
|
|
|
query: slug |
|
|
|
query: dirName, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// Route for each of the versions of this roadmap i.e.
|
|
|
|
// Routes for all the pages inside this directory
|
|
|
|
// `{ '/frontend/2019': { page: '/[roadmap]/[version]', query: 'frontend/2019' } }`
|
|
|
|
...pageFilePaths.reduce((pageRoutes, pageFilePath) => { |
|
|
|
...((roadmap.versions || []).reduce((versionRoutes, version) => { |
|
|
|
const pageFileName = path.basename(pageFilePath, '.md'); |
|
|
|
|
|
|
|
const pageSlug = pageFileName.replace(/^\d+-/, '').toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
...versionRoutes, |
|
|
|
...pageRoutes, |
|
|
|
[`${roadmap.url}/${version}`]: { |
|
|
|
[`${roadmapUrl}/${pageSlug}`]: { |
|
|
|
page: '/[roadmap]/[version]', |
|
|
|
page: '/[roadmap]/[page]', |
|
|
|
query: `${slug}/${version}` |
|
|
|
query: `${roadmapUrl}/${pageSlug}` |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, {})), |
|
|
|
}, {}) |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, {}); |
|
|
|
}, {}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(getRoadmapRoutes()); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Generates the path-map understood by next.js |
|
|
|
* Generates the path-map understood by next.js |
|
|
|
* @returns {{}} |
|
|
|
* @returns {{}} |
|
|
|