-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
115 lines (103 loc) · 2.71 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
const path = require('path');
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const pages = await graphql(`
{
allDatoCmsProject(sort: { fields: position, order: ASC }) {
nodes {
id
slug
seo {
title
}
title
cover {
gatsbyImageData(layout: FULL_WIDTH)
alt
}
about
services
preview
link
challenge
approach
showResult
result
gallery {
gatsbyImageData(layout: FULL_WIDTH)
url
}
}
}
}
`);
const allPages = await graphql(`
{
allDatoCmsProject(sort: { fields: position, order: ASC }) {
edges {
node {
id
slug
title
cover {
url
alt
}
}
}
}
}
`);
pages.data.allDatoCmsProject.nodes.forEach(node => {
function getPagination(projects, currentProject) {
let elements = [];
projects.forEach((project, index) => {
const isThisPage = project.node.slug === currentProject.slug;
if (isThisPage) {
const next = index + 1 === projects.length ? projects[0].node : projects[index + 1].node;
const previous =
index === 0 ? projects[projects.length - 1].node : projects[index - 1].node;
elements.push({ next, previous });
}
});
return elements;
}
let paginationObject = getPagination(allPages.data.allDatoCmsProject.edges, node);
createPage({
path: `/${node.slug}`,
component: path.resolve(__dirname, 'src/templates/project.js'),
context: {
project: node,
pagination: paginationObject,
},
});
});
};
// https://www.gatsbyjs.org/docs/node-apis/#onCreateWebpackConfig
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
'@components': path.resolve(__dirname, 'src/components'),
'@images': path.resolve(__dirname, 'src/images'),
'@pages': path.resolve(__dirname, 'src/pages'),
'@styles': path.resolve(__dirname, 'src/styles'),
'@views': path.resolve(__dirname, 'src/views'),
'@fonts': path.resolve(__dirname, 'src/fonts'),
'@hooks': path.resolve(__dirname, 'src/hooks'),
},
},
});
if (stage === 'build-html' || stage === 'develop-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /locomotive-scroll/,
use: loaders.null(),
},
],
},
});
}
};