-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
80 lines (76 loc) · 2.45 KB
/
next.config.mjs
File metadata and controls
80 lines (76 loc) · 2.45 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
// Security headers (CSP, HSTS, X-Frame-Options, etc.) are handled by the
// hosting layer — CloudFront Response Headers Policy in Phase 2. The Next.js
// `headers()` config is inert when `output: 'export'` is set.
import createMDX from '@next/mdx';
import { readFileSync } from 'node:fs';
import remarkFrontmatter from 'remark-frontmatter';
import remarkGfm from 'remark-gfm';
import remarkCodeTitles from 'remark-flexible-code-titles';
import rehypePrettyCode from 'rehype-pretty-code';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import {
rehypeAttachRawStringsToCodeContainer,
rehypeEnrichCodeContainerMetadata,
} from 'rehype-clipboard-prep-code';
const withMDX = createMDX({
extension: /\.mdx$/,
options: {
remarkPlugins: [
remarkFrontmatter, // strips YAML so MDX compiler ignores it
remarkGfm,
[
remarkCodeTitles,
{
titleTagName: 'CodeBlockTitle',
titleClassName: 'custom-code-title',
titleProperties: (language, title) => ({
['data-language']: language,
title,
}),
},
],
],
// ORDER MATTERS — rehype-clipboard-prep-code plugins bracket rehype-pretty-code
rehypePlugins: [
rehypeAttachRawStringsToCodeContainer, // before pretty-code: reads raw code text
rehypeSlug,
[
rehypePrettyCode,
{
theme: JSON.parse(
readFileSync('./src/styles/greenery-theme.json', 'utf-8'),
),
onVisitLine(node) {
if (node.children.length === 0)
node.children = [{ type: 'text', value: ' ' }];
},
onVisitHighlightedLine(node) {
node?.properties?.className?.push('line--highlighted');
},
onVisitHighlightedWord(node) {
node.properties.className = ['word--highlighted'];
},
},
],
rehypeEnrichCodeContainerMetadata, // after pretty-code: reads data-rehype-pretty-code-fragment
[
rehypeAutolinkHeadings,
{
properties: { className: ['anchor'], ariaLabel: 'Link to section' },
},
],
],
},
});
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
distDir: 'dist',
pageExtensions: ['ts', 'tsx', 'mdx'],
reactStrictMode: false,
poweredByHeader: false,
trailingSlash: true,
images: { unoptimized: true },
};
export default withMDX(nextConfig);