Add pathmap generation

This commit is contained in:
Kamran Ahmed
2019-11-06 20:33:33 +04:00
parent 2cf22c1777
commit 159741f0af
8 changed files with 66 additions and 36 deletions

View File

@@ -6,18 +6,15 @@ export const getRequestedGuide = req => {
return null;
}
// Remove any slashes from the beginning
// Webpack module resolver takes care of the base path
// Look at `config.resolve.modules` in next.config.js
// Remove `.md` from the end
// We need to put that in `require` below to make
// webpack bundle all the markdown files
const path = guide.path.replace(/^\//, '').replace(/\.md$/, '');
// We will use this URL format to find the relevant markdown
// file inside the `/data` directory. For example `/guides/learn-regex`
// has to have `/guides/learn-regex.md` file inside the `data` directory
const path = guide.slug.replace(/^\//, '');
try {
return {
...guide,
component: require(`../${path}.md`).default,
component: require(`../data/${path}.md`).default,
// component: require(guide.path.replace(/^\//, '')).default
};
} catch (e) {