This repository has been archived by the owner on Jul 4, 2022. It is now read-only.
/
gatsby-config.js
167 lines (149 loc) · 3.66 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
const config = () => ({
pathPrefix: '/til',
siteMetadata: metadata(),
plugins: plugins(),
})
const metadata = () => ({
title: "Rico Sta. Cruz's blog",
// Home page title
fullTitle: 'Today I Learned — web development musings semi-daily',
description: 'Regular musings on web development',
// For the feed
siteUrl: 'https://ricostacruz.com/til',
})
const plugins = () => [
'gatsby-plugin-typescript',
'gatsby-plugin-react-helmet',
'gatsby-plugin-postcss',
// Remove unused selectors
{
resolve: 'gatsby-plugin-purgecss',
options: {
printRejected: true,
tailwind: true,
whitelistPatterns: [/:global/],
// It strips out 'dl dl', 'hr', 'nav ul', and other legit selectors
// from sanitize.css
ignore: ['sanitize.css'],
},
},
// Images
...(hasSharp() ? ['gatsby-plugin-sharp'] : []),
// Allow pages in /pages instead of /src/pages
{
resolve: 'gatsby-plugin-page-creator',
options: { path: `${__dirname}/pages` },
},
// Posts
...['2013', '2015', '2017', '2018', '2019', '2020'].map((year) => ({
resolve: 'gatsby-source-filesystem',
options: { name: 'posts', path: `${__dirname}/posts/${year}` },
})),
// MDX Markdown
{
resolve: 'gatsby-plugin-mdx',
options: {
extensions: ['.md', '.mdx'],
gatsbyRemarkPlugins: [
// Put images in a responsive container
...(hasSharp()
? [
{
resolve: 'gatsby-remark-images',
options: { maxWidth: 1400 },
},
]
: []),
// Syntax highlighting
{
resolve: 'gatsby-remark-prismjs',
options: {
aliases: {
sh: 'bash',
dosini: 'ini',
},
},
},
// Support animated GIF's
// See: https://www.gatsbyjs.org/packages/gatsby-remark-images/#supported-formats
'gatsby-remark-copy-linked-files',
],
rehypePlugins: [
// Put h2's into its own section
require('@rstacruz/rehype-sectionize').plugin,
],
},
},
// Reading time
'gatsby-remark-reading-time',
// RSS feed
{
resolve: 'gatsby-plugin-feed',
options: {
query: feedSiteQuery,
feeds: [
{
serialize: ({ query: { site, allMdx } }) => {
return allMdx.edges.map((edge) => {
const { node } = edge
const { frontmatter } = node
const { siteMetadata } = site
return {
title: frontmatter.title,
date: frontmatter.date,
description: frontmatter.description || node.excerpt,
url: siteMetadata.siteUrl + node.fields.slug,
guid: siteMetadata.siteUrl + node.fields.slug,
custom_elements: [{ 'content:encoded': node.html }],
}
})
},
query: feedEntriesQuery,
output: '/rss.xml',
title: "Rico Sta. Cruz's blog",
},
],
},
},
]
function hasSharp() {
try {
require.resolve('sharp')
return true
} catch (e) {
return false
}
}
// To allow gql`...` for syntax highlighting
const gql = String.raw
const feedSiteQuery = gql`
{
site {
siteMetadata {
title
siteUrl
}
}
}
`
const feedEntriesQuery = gql`
{
allMdx(sort: { order: DESC, fields: [frontmatter___date] }) {
edges {
node {
excerpt
html
fields {
slug
}
frontmatter {
title
date
description
}
}
}
}
}
`
module.exports = config()