-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgatsby-node.js
More file actions
45 lines (40 loc) · 1.03 KB
/
gatsby-node.js
File metadata and controls
45 lines (40 loc) · 1.03 KB
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
const readingTime = require('reading-time')
const path = require('path')
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
const writeupTemplate = path.resolve('src/templates/writeup.js')
const writeups = await graphql(`
query Writeups {
allMdx(sort: {frontmatter: {date: DESC}}) {
nodes {
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
}
`)
if (writeups.errors) {
reporter.panicOnBuild('Error querying for writeups')
return
}
writeups.data.allMdx.nodes.forEach(({ frontmatter, internal }) => {
createPage({
path: frontmatter.slug,
component: `${writeupTemplate}?__contentFilePath=${internal.contentFilePath}`,
})
})
}
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions
if (node.internal.type === `Mdx`) {
createNodeField({
node,
name: `timeToRead`,
value: readingTime(node.body)
})
}
}