-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
62 lines (57 loc) · 1.81 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
58
59
60
61
62
const path = require('path');
const { slash } = require(`gatsby-core-utils`)
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allWordpressPost(filter: {categories: { elemMatch: {wordpress_id: {eq: 358}}}}) {
edges {
node {
id
slug
}
}
}
allItems(filter: {snippet:{thumbnails: {standard: {url:{ne: null}}}}}, sort: {fields: contentDetails___videoPublishedAt, order: DESC}) {
totalCount
edges {
node {
contentDetails {
videoId
videoPublishedAt(formatString: "MMMM Do, YYYY")
}
}
}
}
}
`)
const postTemplate = path.resolve(`./src/templates/post.js`)
result.data.allWordpressPost.edges.forEach(edge => {
createPage({
// will be the url for the page
path: `/factcheck/${edge.node.slug}`,
// specify the component template of your choice
component: slash(postTemplate),
// In the ^template's GraphQL query, 'id' will be available
// as a GraphQL variable to query for this posts's data.
context: {
id: edge.node.id,
},
})
})
const videoTemplate = path.resolve(`./src/templates/videos.js`)
result.data.allItems.edges.forEach(edge => {
if(!edge.node.contentDetails) return false;
createPage({
// will be the url for the page
path: `/videos/${edge.node.contentDetails.videoId}`,
// specify the component template of your choice
component: slash(videoTemplate),
// In the ^template's GraphQL query, 'id' will be available
// as a GraphQL variable to query for this posts's data.
context: {
id: edge.node.contentDetails.videoId,
},
})
})
};