-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
gatsby-config.mjs
98 lines (88 loc) · 2.66 KB
/
gatsby-config.mjs
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
import path from 'path'
import fs from 'fs'
import remarkGfm from 'remark-gfm'
import remarkFm from 'remark-frontmatter'
const {NODE_ENV, GATSBY_CONTENT_ALLOW, GATSBY_CONTENT_IGNORE, GATSBY_CONTENT_DIR = 'content'} = process.env
const DEV = NODE_ENV === 'development'
const CONTENT_DIR = path.resolve(GATSBY_CONTENT_DIR)
const walkDirs = dir => {
const dirs = fs
.readdirSync(dir)
.filter(d => fs.statSync(path.join(dir, d)).isDirectory())
.map(p => path.join(dir, p))
const nested = dirs.flatMap(d => walkDirs(d))
return [...dirs, ...nested]
}
const getContentOptions = () => {
if (!DEV || (!GATSBY_CONTENT_ALLOW && !GATSBY_CONTENT_IGNORE)) {
return
}
const allowContent = (GATSBY_CONTENT_ALLOW ?? '').split(',').filter(Boolean)
const ignoreContent = (GATSBY_CONTENT_IGNORE ?? '').split(',').filter(Boolean)
const paths = walkDirs(CONTENT_DIR)
.map(p => path.relative(CONTENT_DIR, p))
.sort()
.reduce(
(acc, p) => {
const allow = allowContent.length ? allowContent.includes(p) : null
const ignore = ignoreContent.length ? ignoreContent.includes(p) : null
if (ignore === true || allow === false) {
acc.ignore.push(p)
} else {
acc.include.push(p)
}
return acc
},
{include: [], ignore: []},
)
const ignoreGlobs = paths.ignore.map(p => path.join('**', p, '**'))
console.log(`Only including the following partial content in dev mode`)
console.log(`Allow:\n - ${paths.include.join('\n - ')}`)
console.log(`Ignore:\n - ${ignoreGlobs.join('\n - ')}`)
return {
ignore: ignoreGlobs,
}
}
const config = {
trailingSlash: 'never',
siteMetadata: {
title: 'npm Docs',
shortName: 'npm',
description: 'Documentation for the npm registry, website, and command-line interface',
lang: 'en',
imageUrl: 'https://user-images.githubusercontent.com/29712634/81721690-e2fb5d80-9445-11ea-8602-4b2294c964f3.png',
repositoryUrl: 'https://github.com/npm/documentation',
},
flags: {
DEV_SSR: !!process.env.GATSBY_DEV_SSR,
},
plugins: [
'gatsby-plugin-postcss',
'gatsby-plugin-styled-components',
'gatsby-transformer-yaml',
{
resolve: 'gatsby-plugin-mdx',
options: {
mdxOptions: {
remarkPlugins: [remarkGfm, remarkFm],
},
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'content',
path: CONTENT_DIR,
...getContentOptions(),
},
},
{
resolve: 'gatsby-plugin-manifest',
options: {
icon: path.resolve('./src/favicon.png'),
},
},
'gatsby-plugin-meta-redirect',
],
}
export default config