-
Notifications
You must be signed in to change notification settings - Fork 50
/
gatsby-config.js
219 lines (212 loc) · 5.6 KB
/
gatsby-config.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
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
/* eslint-disable @typescript-eslint/no-var-requires */
require('source-map-support').install()
require('ts-node').register({
compilerOptions: {
module: 'commonjs',
target: 'es2017'
}
})
const config = require('./src/config/siteConfig').default
const pathPrefix = config.pathPrefix === '/' ? '' : config.pathPrefix
const { generatePath } = require('./src/utils/paths')
const { removeStopwords } = require('stopword')
const moment = require('moment')
const _ = require('lodash')
const rssQuery = `
{
allMdx(
sort: { order: DESC, fields: [frontmatter___date, frontmatter___title] },
limit: 10,
) {
edges {
node {
excerpt
html
fields { path }
frontmatter {
title
date
}
}
}
}
}
`
const feedSerializer = ({ query: { site, allMdx } }) => {
return allMdx.edges.map((edge) => {
return Object.assign({}, edge.node.frontmatter, {
description: edge.node.excerpt,
date: edge.node.frontmatter.date,
url: site.siteMetadata.siteUrl + edge.node.fields.path,
guid: site.siteMetadata.siteUrl + edge.node.fields.path,
custom_elements: [{ 'content:encoded': edge.node.html }]
})
})
}
const feedTemplate = {
title: "Ash Furrow's Blog",
match: '^/blog/',
serialize: feedSerializer,
query: rssQuery
}
const gatsbyRemarkPlugins = [
{
resolve: 'gatsby-remark-external-links',
options: {
target: '_blank',
rel: 'nofollow noopener noreferrer'
}
},
{
resolve: 'gatsby-remark-prismjs',
options: {
aliases: {
sh: 'shell'
}
}
},
'gatsby-remark-autolink-headers',
'gatsby-remark-smartypants',
{
resolve: 'gatsby-remark-images',
options: {
maxWidth: 1200
}
},
{
resolve: 'gatsby-remark-copy-linked-files',
options: {
ignoredFileExtensions: ['jpg', 'jpeg', 'png']
}
}
]
module.exports = {
pathPrefix: config.pathPrefix,
siteMetadata: {
title: config.siteTitle,
description: config.siteDescription,
siteUrl: config.siteUrl + pathPrefix
},
plugins: [
'gatsby-plugin-sharp',
'gatsby-plugin-instagram-embed',
'gatsby-plugin-react-helmet',
'gatsby-plugin-styled-components',
'gatsby-plugin-offline',
'gatsby-plugin-typescript',
'gatsby-plugin-sass',
'gatsby-plugin-sitemap',
'gatsby-plugin-lodash',
'gatsby-plugin-root-import',
{
resolve: `gatsby-plugin-feed`,
options: {
// NOTE: The feeds don't work in the development environment, only in the build env.
// See: https://github.com/gatsbyjs/gatsby/discussions/31484
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
...feedTemplate,
output: '/feed.xml'
},
{
...feedTemplate,
output: '/feed.rss.xml'
}
]
}
},
{
resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
options: {
// Fields to index
fields: [`title`, `body`, `date`],
// How to resolve each field`s value for a supported node type
resolvers: {
// For any node of type MarkdownRemark, list how to resolve the fields` values
Mdx: {
title: (node) => node.frontmatter.title,
path: (node) => generatePath(node.frontmatter.title),
// We want to index the blog posts but we want to keep the search index small
// So let's do the following compromises:
// - use the raw markdown, no html
// - drop the yaml frontmatter
// - do stopword pre-filtering
// The plugin doesn't distinguish between including something in the index and making it accessible in the document store.
body: (node) => {
const htmlRemovedBody = node.rawBody.replace(/<[^>]+>/g, '')
// Remove yaml frontmatter
const body = _.drop(htmlRemovedBody.split('---'), 2).join(' ')
return removeStopwords(body.split(' ')).join(' ')
},
date: (node) => moment(node.frontmatter.date).format('MMMM D, YYYY')
}
},
// Optional filter to limit indexed nodes
filter: (node) => node.frontmatter.tags !== 'exempt'
}
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'blog',
path: `${__dirname}/blog`
}
},
{
resolve: 'gatsby-plugin-mdx',
options: {
defaultLayouts: {
blog: require.resolve('./src/templates/Post.tsx'),
default: require.resolve('./src/layouts/MDXLayout.tsx')
},
gatsbyRemarkPlugins
}
},
{
resolve: 'gatsby-plugin-web-font-loader',
options: {
typekit: {
id: 'fmr6vlo'
}
}
},
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: gatsbyRemarkPlugins
}
},
{
resolve: 'gatsby-plugin-typography',
options: {
pathToConfigModule: 'src/utils/typography.ts'
}
},
{
resolve: 'gatsby-plugin-manifest',
options: {
name: config.siteTitle,
short_name: config.siteTitleAlt,
description: config.siteDescription,
start_url: config.pathPrefix,
background_color: config.backgroundColor,
display: 'standalone',
icon: config.favicon
}
},
'gatsby-plugin-catch-links',
'gatsby-plugin-netlify'
]
}