forked from subvisual/2018.mirrorconf.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-pages.js
39 lines (32 loc) · 870 Bytes
/
create-pages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const path = require(`path`);
const query = folder => `
{
allMarkdownRemark(filter: { fileAbsolutePath: {regex: "/(${folder})/.*/"}}) {
edges { node { frontmatter { slug } } }
}
}
`;
const WORKSHOPS = {
query: query('workshops'),
template: 'src/templates/workshop.js',
};
const render = createPage => templatePath => result => {
if (result.errors) {
Promise.reject(result.errors);
}
const component = path.resolve(templatePath);
const { edges } = result.data.allMarkdownRemark;
return edges.map(({ node: { frontmatter: { slug } } }) =>
createPage({
component,
path: slug,
context: { slug },
})
);
};
module.exports = ({ boundActionCreators: { createPage }, graphql }) => {
const renderFn = render(createPage);
return Promise.all([
graphql(WORKSHOPS.query).then(renderFn(WORKSHOPS.template)),
]);
};