-
Notifications
You must be signed in to change notification settings - Fork 29
/
gatsby-node.js
165 lines (156 loc) · 3.84 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const locales = require("./locales/config.json").map((l) => l.code);
const path = require("path");
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");
/** Removes the useless pages (ex: /en/team.fr/)
* Changes path for files with extensions: /fr/team.fr/ -> /fr/team/
* Duplicates the french pages to create entrypoints without explicit languages: https://github.com/gatsbyjs/themes/issues/124
*/
exports.onCreatePage = ({ page, actions }) => {
const { createPage, deletePage } = actions;
// /en/team.fr/ -> prefix: en; suffix: en
const extensionMatch =
/\/(?:(?<prefix>[a-z]{2})\/)?[^.]*(?:\.(?<suffix>[a-z]{2}))?\//.exec(
page.path
);
if (extensionMatch) {
let pathWithoutSuffix = page.path;
if (
extensionMatch.groups.suffix &&
(extensionMatch.groups.prefix === extensionMatch.groups.suffix ||
(!extensionMatch.groups.prefix &&
extensionMatch.groups.suffix === "fr"))
) {
pathWithoutSuffix = page.path
.replace(`.${extensionMatch.groups.suffix}/`, "/")
.replace("/index/", "/");
createPage({
...page,
path: pathWithoutSuffix,
});
}
if (extensionMatch.groups.suffix) {
deletePage(page);
}
}
};
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions;
// Query for markdown nodes to use in creating pages.
// A ajouter
// openfeedbackId
// cancelled
// youtube
// slides
const { data, errors } = await graphql(
`
{
allSessionsYaml {
edges {
node {
key
slot
speakers
tags
talkType
title
room
language
complexity
abstract
openfeedbackId
youtube
}
}
}
allSpeakersYaml {
edges {
node {
key
name
feature
city
company
companyLogo
photoUrl
bio
socials {
twitter
github
linkedin
instagram
website
}
}
}
}
allBlogsYaml {
edges {
node {
key
title
image
date
content
}
}
}
}
`
);
if (errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
// Sessions
const sessionPageTemplate = path.resolve(
"src/components/session/sessionPageTemplate.tsx"
);
data.allSessionsYaml.edges.forEach(({ node: session }) => {
const path = "sessions/" + session.key;
createPage({
path,
component: sessionPageTemplate,
context: {
session,
},
});
});
// Speakers
const speakerPageTemplate = path.resolve(
"src/components/speakers/speakerPageTemplate.tsx"
);
data.allSpeakersYaml.edges.forEach(({ node: speaker }) => {
const path = "speakers/" + speaker.key;
createPage({
path,
component: speakerPageTemplate,
context: {
speaker,
},
});
});
// Blogs
const blogPageTemplate = path.resolve(
"src/components/blog/blogPageTemplate.tsx"
);
data.allBlogsYaml.edges.forEach(({ node: blog }) => {
const path = "blog/" + blog.key;
createPage({
path,
component: blogPageTemplate,
context: {
blog,
},
});
});
};
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
plugins: [
new FilterWarningsPlugin({
exclude:
/mini-css-extract-plugin[^]*Conflicting order. Following module has been added:/,
}),
],
});
};