forked from geeksblabla/geeksblabla.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
186 lines (165 loc) · 4.21 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const path = require("path")
const _ = require("lodash")
//const paginate = require("gatsby-awesome-pagination")
//const PAGINATION_OFFSET = 7
const createPosts = (createPage, createRedirect, edges) => {
edges.forEach(({ node }, i) => {
const prev = i === 0 ? null : edges[i - 1].node
const next = i === edges.length - 1 ? null : edges[i + 1].node
const pagePath = node.fields.slug
if (node.fields.redirects) {
node.fields.redirects.forEach(fromPath => {
createRedirect({
fromPath,
toPath: pagePath,
redirectInBrowser: true,
isPermanent: true,
})
})
}
createPage({
path: pagePath,
component: path.resolve(`./src/templates/blabla.js`),
context: {
id: node.id,
prev,
next,
},
})
})
}
exports.createPages = async ({ actions, graphql }) => {
const result = await graphql(
`
{
allMdx(
filter: { frontmatter: { published: { ne: false } } }
sort: { order: DESC, fields: [frontmatter___date] }
) {
edges {
node {
id
fileAbsolutePath
parent {
... on File {
name
sourceInstanceName
}
}
excerpt(pruneLength: 250)
fields {
title
slug
date
}
}
}
}
}
`
)
if (result.errors) {
throw result.errors
}
const { edges } = result.data.allMdx
const { createRedirect, createPage } = actions
createPosts(createPage, createRedirect, edges)
}
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === `Mdx`) {
const parent = getNode(node.parent)
const titleSlugged = _.join(_.drop(parent.name.split("-"), 3), "-")
const slug = "blablas/" + _.kebabCase(node.frontmatter.title)
createNodeField({
name: "id",
node,
value: node.id,
})
createNodeField({
name: "published",
node,
value: node.frontmatter.published,
})
createNodeField({
name: "title",
node,
value: node.frontmatter.title,
})
createNodeField({
name: "slug",
node,
value: slug,
})
createNodeField({
name: "date",
node,
value: node.frontmatter.date ? node.frontmatter.date.split(" ")[0] : "",
})
createNodeField({
name: "duration",
node,
value: node.frontmatter.duration ? node.frontmatter.duration : "01:00",
})
createNodeField({
name: "tags",
node,
value: node.frontmatter.tags || [],
})
const path =
node.fileAbsolutePath.substring(
node.fileAbsolutePath.indexOf(
"/",
node.fileAbsolutePath.indexOf("blablas")
)
) || ""
createNodeField({
name: "repoLink",
node,
value: `/~https://github.com/DevC-Casa/geeksblabla.com/tree/master/blablas${path}`,
})
createNodeField({
name: "url",
node,
value:
node.frontmatter.url ||
"https://www.facebook.com/groups/DevC.Casablanca/",
})
createNodeField({
name: "video",
node,
value: node.frontmatter.video || "",
})
}
}
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
/*
* During the build step, `auth0-js` will break because it relies on
* browser-specific APIs. Fortunately, we don’t need it during the build.
* Using Webpack’s null loader, we’re able to effectively ignore `auth0-js`
* during the build. (See `src/utils/auth.js` to see how we prevent this
* from breaking the app.)
*/
actions.setWebpackConfig({
module: {
rules: [
{
test: /auth0-js/,
use: loaders.null(),
},
],
},
})
}
}
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, "src"), "node_modules"],
alias: {
$components: path.resolve(__dirname, "src/components"),
},
},
})
}