generated from oracle-samples/oce-gatsby-blog-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
84 lines (78 loc) · 2.14 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (c) 2021 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/node-apis/
*/
const path = require('path');
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
const articlesListTemplate = path.resolve(
'src/templates/ArticlesListTemplate.jsx',
);
const articleDetailsTemplate = path.resolve(
'src/templates/ArticleDetailsTemplate.jsx',
);
// Query for markdown nodes to use in creating pages.
// You can query for whatever data you want to create pages for e.g.
// products, portfolio items, landing pages, etc.
// Variables can be added as the second function parameter
return graphql(`
{
topicsListQuery : allOceAsset(
filter: {
oceType: { eq: "OCEGettingStartedHomePage" }
name: { eq: "HomePage" }
}
) {
nodes {
topics {
id
}
}
}
articlesListQuery: allOceAsset(
filter: { oceType: { eq: "OCEGettingStartedArticle" } }
) {
nodes {
oceId
}
}
}
`).then((result) => {
if (result.errors) {
throw result.errors;
}
// Create topic pages.
const toplevel = result.data.topicsListQuery.nodes[0];
const { topics } = toplevel;
topics.forEach((topic) => {
const topicId = topic.id;
createPage({
path: `topic/${topicId}`,
component: articlesListTemplate,
context: {
topicId,
buildTag: process.env.BUILD_TAG,
},
}); // end createpage for topic
});
// Create articles pages.
const articles = result.data.articlesListQuery.nodes;
articles.forEach((article) => {
const articleId = article.oceId;
createPage({
// Path for this page — required
path: `article/${articleId}`,
component: articleDetailsTemplate,
context: {
articleId,
buildTag: process.env.BUILD_TAG,
},
});
});
});
};