-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.mjs
143 lines (138 loc) · 3.23 KB
/
next.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
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
import { merge } from 'webpack-merge'
import mdx from '@next/mdx'
import rehypePrettyCode from 'rehype-pretty-code'
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeToc from '@stefanprobst/rehype-extract-toc'
import rehypeTocExport from '@stefanprobst/rehype-extract-toc/mdx'
import { getHighlighter, BUNDLED_LANGUAGES } from 'shiki'
import { parse } from 'acorn'
import { h } from 'hastscript'
import stackWrapper from './src/lib/stack-wrapper.mjs'
const withMdx = mdx({
options: {
providerImportSource: '@mdx-js/react',
remarkPlugins: [stackWrapper],
rehypePlugins: [
rehypeSlug,
[
rehypeAutolinkHeadings,
{
content: h('span', '#'),
properties: {
ariaHidden: true,
tabIndex: -1,
class: 'heading-anchor-link',
},
},
],
[
createNextStaticProps,
`{
meta,
tableOfContents,
}`,
],
[
rehypePrettyCode,
{
theme: 'material-palenight',
getHighlighter: options =>
getHighlighter({
...options,
langs: [
...BUNDLED_LANGUAGES,
{
id: 'groq',
scopeName: 'source.groq',
path: '../../vscode-sanity/grammars/groq.json',
},
],
}),
onVisitLine(node) {
// Prevent lines from collapsing in `display: grid` mode, and allow
// empty lines to be copy/pasted.
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }]
}
},
},
],
rehypeToc,
rehypeTocExport,
],
},
})
function createNextStaticProps(map) {
return function transformer(tree) {
tree.children.push({
type: 'mdxjsEsm',
data: {
estree: parse(
`
export const getStaticProps = () => ({
props: ${map},
})
`,
{
sourceType: 'module',
},
),
},
})
}
}
export default withMdx({
pageExtensions: ['ts', 'tsx', 'mdx'],
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.sanity.io',
},
{
protocol: 'https',
hostname: '*.mzstatic.com',
},
],
formats: ['image/avif', 'image/webp'],
},
experimental: {
browsersListForSwc: true,
legacyBrowsers: false,
},
async rewrites() {
return [
{
source: '/feed',
destination: '/feed.json',
},
]
},
async headers() {
return [
{
source: '/feed',
headers: [
{
key: 'Content-Type',
value: 'application/feed+json; charset=utf-8',
},
],
},
]
},
webpack: (config, options) =>
merge(config, {
async entry() {
if (!options.isServer || options.nextRuntime !== 'nodejs') {
return config.entry
}
const entry = await config.entry()
return {
...entry,
'render-json-feed': './src/scripts/render-json-feed.tsx',
}
},
}),
})