forked from availproject/old-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
106 lines (95 loc) · 2.5 KB
/
next.config.ts
File metadata and controls
106 lines (95 loc) · 2.5 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
import nextra from 'nextra'
function isExportNode(node, varName: string) {
if (node.type !== 'mdxjsEsm') return false
const [n] = node.data.estree.body
if (n.type !== 'ExportNamedDeclaration') return false
const name = n.declaration?.declarations?.[0].id.name
if (!name) return false
return name === varName
}
const DEFAULT_PROPERTY_PROPS = {
type: 'Property',
kind: 'init',
method: false,
shorthand: false,
computed: false
}
export function createAstObject(obj) {
return {
type: 'ObjectExpression',
properties: Object.entries(obj).map(([key, value]) => ({
...DEFAULT_PROPERTY_PROPS,
key: { type: 'Identifier', name: key },
value:
value && typeof value === 'object' ? value : { type: 'Literal', value }
}))
}
}
// eslint-disable-next-line unicorn/consistent-function-scoping
const rehypeOpenGraphImage = () => ast => {
const frontMatterNode = ast.children.find(node =>
isExportNode(node, 'metadata')
)
if (!frontMatterNode) {
return
}
const { properties } =
frontMatterNode.data.estree.body[0].declaration.declarations[0].init
const title = properties.find(o => o.key.value === 'title')?.value.value
if (!title) {
return
}
const [prop] = createAstObject({
openGraph: createAstObject({
images: `https://nextra.site/og?title=${title}`
})
}).properties
properties.push(prop)
}
const withNextra = nextra({
search: {
codeblocks: false
},
latex: true,
defaultShowCopyCode: true,
mdxOptions: {
rehypePlugins: [
// Provide only on `build` since turbopack on `dev` supports only serializable values
...(process.env.NODE_ENV === 'production' ? [rehypeOpenGraphImage] : [])
]
},
whiteListTagsStyling: ['figure', 'figcaption']
})
const nextConfig = withNextra({
reactStrictMode: true,
eslint: {
// ESLint behaves weirdly in this monorepo.
ignoreDuringBuilds: true
},
redirects: async () => [
],
webpack(config) {
const allowedSvgRegex = /components\/icons\/.+\.svg$/
const fileLoaderRule = config.module.rules.find(rule =>
rule.test?.test?.('.svg')
)
fileLoaderRule.exclude = allowedSvgRegex
config.module.rules.push({
test: allowedSvgRegex,
use: ['@svgr/webpack']
})
return config
},
experimental: {
turbo: {
rules: {
'./components/icons/*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js'
}
}
},
optimizePackageImports: ['@components/icons']
}
})
export default nextConfig