forked from namc-utah/namc-usu.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
39 lines (37 loc) · 1.08 KB
/
gatsby-node.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
/**
* A note about typescript:
* It is technically possible to convert this to typescript but the debugging becomes much more complicated
* so a decision was made not to pursue this.
*/
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
const pageTemplate = require.resolve(`./src/templates/PageTemplate`)
return graphql(`
{
pages: allMarkdownRemark {
nodes {
fields {
slug
}
}
}
}
`).then((result) => {
if (result.errors) {
return Promise.reject(result.errors)
}
const pages = result.data.pages.nodes
pages.forEach((page) => {
const slug = page.fields.slug
const deIndexedSlug = slug.replace(/(.*)index/, '$1')
createPage({
path: deIndexedSlug,
component: pageTemplate,
context: {
deIndexedSlug,
slug
}
})
})
})
}