-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
135 lines (123 loc) · 3.19 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const path = require("path");
// Creating the blog list page and blog post pages.
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return new Promise((resolve, reject) => {
const blogListPage = path.resolve(
`${__dirname}/src/components/Website/Blog/BlogPostList.js`
);
const blogPostPage = path.resolve(
`${__dirname}/src/components/Website/Blog/BlogPost.js`
);
graphql(`
query {
posts: allSanityBlogPost {
nodes {
id
slug {
current
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors);
}
// Create blog post pages
const posts = result.data.posts.nodes;
const postsPerPage = 8;
const numberOfPostPages = Math.ceil(posts.length / postsPerPage);
Array.from({ length: numberOfPostPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/blog` : `/blog/${i + 1}`,
component: blogListPage,
context: {
first: postsPerPage,
skip: i * postsPerPage,
pageNumber: i + 1,
hasNextPage: i + 1 < posts.length / postsPerPage,
hasPrevPage: posts.length / postsPerPage - (i + 1) < i,
nextPageLink: `/blog/${i + 2}`,
prevPageLink: i === 0 || 1 ? "/blog" : `/blog/${i}`,
},
});
});
posts.forEach(post => {
const slug = `/blog/${post.slug.current}`;
const id = post.id;
createPage({
path: slug,
component: blogPostPage,
context: {
slug,
id,
},
});
});
resolve();
});
});
};
// Create the client side routing side of the app
exports.onCreatePage = async ({ page, actions }) => {
const { createPage } = actions;
// page.matchPath is a special key that's used for matching pages
// only on the client.
if (page.path.match(/^\/app/)) {
page.matchPath = "/app/*";
// Update the page.
createPage(page);
}
};
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {
actions.setWebpackConfig({
module: {
rules:
stage === "build-html"
? [
{
test: /ThrowPropsPlugin/,
use: loaders.null(),
},
{
test: /DrawSVGPlugin/,
use: loaders.null(),
},
]
: [],
},
resolve: {
alias: {
TweenLite: path.resolve(
"node_modules",
"gsap/src/uncompressed/TweenLite.js"
),
TweenMax: path.resolve(
"node_modules",
"gsap/src/uncompressed/TweenMax.js"
),
TimelineLite: path.resolve(
"node_modules",
"gsap/src/uncompressed/TimelineLite.js"
),
TimelineMax: path.resolve(
"node_modules",
"gsap/src/uncompressed/TimelineMax.js"
),
},
},
});
};