-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
150 lines (128 loc) · 3 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
const fs = require('fs')
const path = require('path')
const {URL} = require('url')
const rimraf = require('rimraf')
const slugify = require('@sindresorhus/slugify')
const {createFilePath} = require('gatsby-source-filesystem')
const {zipFunctions} = require('@netlify/zip-it-and-ship-it')
const config = require('./config/website')
const onCreateWebpackConfig = ({actions}) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
})
}
const onCreateNode = (...args) => {
if (args[0].node.internal.type === `Mdx`) {
onCreateMdxNode(...args)
}
}
// eslint-disable-next-line complexity
function onCreateMdxNode({node, getNode, actions}) {
const {createNodeField} = actions
let slug =
node.frontmatter.slug || createFilePath({node, getNode, basePath: `pages`})
let {isProject} = false
if (node.fileAbsolutePath.includes('content/projects/')) {
isProject = true
slug = `/projects/${
node.frontmatter.slug || slugify(node.frontmatter.title)
}`
}
createNodeField({
name: 'id',
node,
value: node.id,
})
createNodeField({
name: 'title',
node,
value: node.frontmatter.title,
})
createNodeField({
name: 'author',
node,
value: node.frontmatter.author || 'Maciek Sitkowski',
})
createNodeField({
name: 'description',
node,
value: node.frontmatter.description,
})
createNodeField({
name: 'slug',
node,
value: slug,
})
const productionUrl = new URL(config.siteUrl)
productionUrl.pathname = slug
createNodeField({
name: 'productionUrl',
node,
value: productionUrl.toString(),
})
createNodeField({
name: 'date',
node,
value: node.frontmatter.date ? node.frontmatter.date.split(' ')[0] : '',
})
createNodeField({
name: 'banner',
node,
value: node.frontmatter.banner,
})
createNodeField({
name: 'categories',
node,
value: node.frontmatter.categories || [],
})
createNodeField({
name: 'keywords',
node,
value: node.frontmatter.keywords || [],
})
createNodeField({
name: 'isProject',
node,
value: isProject,
})
createNodeField({
name: 'repoUrl',
node,
value: node.frontmatter.repoUrl,
})
createNodeField({
name: 'homepageUrl',
node,
value: node.frontmatter.homepageUrl,
})
createNodeField({
name: 'isInDevelopment',
node,
value: node.frontmatter.isInDevelopment || false,
})
}
const onPostBuild = async () => {
if (process.env.gatsby_executing_command === 'develop') {
return
}
const srcLocation = path.join(__dirname, `netlify/functions`)
const outputLocation = path.join(__dirname, `public/functions`)
if (fs.existsSync(outputLocation)) {
rimraf.sync(outputLocation)
}
fs.mkdirSync(outputLocation)
await zipFunctions(srcLocation, outputLocation)
}
module.exports = {
// createPages,
onCreateWebpackConfig,
onCreateNode,
onPostBuild,
}
/*
eslint
consistent-return: "off",
max-statements: "off",
*/