-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
28 lines (25 loc) · 853 Bytes
/
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
const path = require("path")
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
//the query below allows to get an array with all the topics (mentioned only once without repetitions)
const result = await graphql(`
query GetTopics {
allContentfulBlog {
distinct(field: topics)
}
}
`)
//console.log(result)
//for each topic a page is created using the topic-template.js file as a base
result.data.allContentfulBlog.distinct.forEach(topic => {
//const topicSlug = slugify(topic, { lower: true })
//createPage is a function taking an object as a parameter containing path, component, context
createPage({
path: `/blogs/${topic}`,
component: path.resolve(`src/templates/topic-template.js`),
context: {
topic: topic,
},
})
})
}