-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
57 lines (52 loc) · 1.46 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const path = require('path')
const fs = require('fs')
const get = require('lodash/get')
const articlesQuery = `
query {
allMarkdownRemark {
edges {
node {
frontmatter {
slug
img
updated
}
}
}
}
}
`
const createIndexPage = ({ createPage }) => {
createPage({
path: '/',
component: path.resolve('./src/templates/blog-index.tsx'),
})
}
const createArticlesPages = (graphql, { createPage }) => {
return graphql(articlesQuery).then((result) => {
const { errors, data } = result
if (errors) {
throw errors
}
const posts = get(data, 'allMarkdownRemark.edges', [])
posts.forEach(({ node }) => {
const { img, slug, updated } = get(node, 'frontmatter', {})
createPage({
path: `${slug}/`,
component: path.resolve('./src/templates/blog-article.tsx'),
context: { slug, img, updated },
})
})
})
}
exports.createPages = ({ graphql, actions }) => {
createIndexPage(actions)
return createArticlesPages(graphql, actions)
}
exports.onPostBuild = ({ reporter }) => {
reporter.info(`Copying sitemap.xml to root because gatsby-plugin-sitemap is crappy`)
const inputSitemap = path.resolve(__dirname, 'public', 'sitemap', 'sitemap-0.xml')
const outputSitemap = path.resolve(__dirname, 'public', 'sitemap.xml')
fs.copyFileSync(inputSitemap, outputSitemap)
reporter.success(`sitemap.xml copied to root successfully!`)
}