-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathgatsby-config.js
More file actions
233 lines (223 loc) · 5.96 KB
/
gatsby-config.js
File metadata and controls
233 lines (223 loc) · 5.96 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
'use strict'
const { URL } = require('url')
const path = require('path')
const log = (...args) => {
if (process.env.DEBUG) {
console.log(...args)
}
}
const {
STRIPE_KEY,
PAYMENT_API_KEY,
PAYMENT_ENDPOINT,
SITE_URL,
CANONICAL_URL,
CDN_URL
} = require('./env')
module.exports = {
trailingSlash: 'never',
flags: {
DEV_SSR: true, // better 1:1 production behavior
FAST_DEV: true,
PARALLEL_SOURCING: true,
PRESERVE_FILE_DOWNLOAD_CACHE: true
},
siteMetadata: {
// Basic
name: 'Microlink',
author: 'Microlink HQ',
headline: 'Microlink | Headless Browser API: Screenshot, PDF & Previews',
description:
'Turn any URL into structured data. The all-in-one API for browser automation: screenshots, PDFs, scraping, and link previews. No infrastructure to manage.',
siteUrl: SITE_URL,
canonicalUrl: CANONICAL_URL,
twitter: '@microlinkhq',
image: new URL('logo/banner.jpeg', CDN_URL).toString(),
logo: new URL('logo/logo.png', CDN_URL).toString(),
// Slack previsualization
dataLabel1: 'API',
dataLabel2: 'Documentation',
dataValue1: 'api.microlink.io',
dataValue2: 'microlink.io/docs',
// additional
paymentApiKey: PAYMENT_API_KEY,
paymentEndpoint: PAYMENT_ENDPOINT,
stripeKey: STRIPE_KEY,
cdnUrl: CDN_URL
},
plugins: [
'gatsby-plugin-styled-components',
'gatsby-plugin-catch-links',
'gatsby-transformer-javascript-frontmatter',
{
resolve: 'gatsby-plugin-sass',
options: {
sassOptions: {
precision: 8
},
postCssPlugins: require('./postcss.config').plugins
}
},
'gatsby-transformer-json',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'data',
path: path.join(__dirname, 'data')
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: path.join(__dirname, 'src/pages'),
name: 'pages'
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: path.join(__dirname, 'src/content'),
name: 'content'
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: path.join(__dirname, 'data/skills-content'),
name: 'skills-content'
}
},
{
resolve: 'gatsby-plugin-canonical-urls',
options: {
siteUrl: CANONICAL_URL
}
},
{
resolve: 'gatsby-plugin-mdx',
options: {
extensions: ['.mdx', '.md'],
mdxOptions: {
remarkPlugins: [require('remark-gfm').default],
rehypePlugins: [require('rehype-slug').default]
}
}
},
'gatsby-transformer-yaml',
{
resolve: 'gatsby-plugin-sitemap',
/* activate fields { slug, lastmod } once we find a workaround for Vercel git history */
options: {
excludes: [
'/404',
'/404.html',
'/dev-404-page',
'/offline-plugin-app-shell-fallback',
'/payment',
'/payment/update'
],
query: `
{
site {
siteMetadata {
siteUrl
}
}
allSitePage {
nodes {
path
}
}
allMdx {
edges {
node {
fields {
slug
lastmod
}
frontmatter {
date
}
}
}
}
allFile(filter: { sourceInstanceName: { eq: "pages" } }) {
nodes {
absolutePath
relativePath
relativeDirectory
name
mtime
fields {
lastmod
}
}
}
}
`,
resolvePages: ({
allSitePage: { nodes: allPages },
allMdx: { edges: mdxPages },
allFile: { nodes: pageFiles }
}) => {
const mdxMap = {}
if (mdxPages && Array.isArray(mdxPages)) {
mdxPages.forEach(({ node }) => {
const slug = node.fields?.slug
const lastmod = node.fields?.lastmod || node.frontmatter?.date
if (slug && lastmod) {
const normalizedSlug =
slug.endsWith('/') && slug.length > 1
? slug.slice(0, -1)
: slug
mdxMap[normalizedSlug] = lastmod
}
})
}
const pagesMap = {}
if (pageFiles && Array.isArray(pageFiles)) {
pageFiles.forEach(file => {
let pagePath = null
if (file.relativeDirectory === '') {
if (file.name === 'index') {
pagePath = '/'
} else {
pagePath = `/${file.name}`
}
} else {
const dirPath = file.relativeDirectory.replace(/\\/g, '/')
if (file.name === 'index') {
pagePath = `/${dirPath}`
} else {
pagePath = `/${dirPath}/${file.name}`
}
}
if (pagePath) {
const lastmod = file.fields?.lastmod || file.mtime
if (lastmod) {
pagesMap[pagePath] = lastmod
}
}
})
}
if (!allPages || !Array.isArray(allPages)) {
return []
}
return allPages.map(page => {
const lastmod = mdxMap[page.path] || pagesMap[page.path] || null
return { ...page, lastmod }
})
},
serialize: ({ path: url, lastmod }) => {
if (!lastmod) {
log('not lastmod found', { url, lastmod })
if (!url.startsWith('/recipes')) {
throw new Error(`not lastmod found for '${url}'`)
}
}
return { url, lastmod }
}
}
}
].filter(Boolean)
}