forked from DARIAH-ERIC/dariah-campus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
195 lines (186 loc) · 5.16 KB
/
next.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/** @typedef {import('@/i18n/i18n.config').Locale} Locale */
/** @typedef {import('next').NextConfig & {i18n?: {locales: Array<Locale>; defaultLocale: Locale}}} NextConfig */
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import createBundleAnalyzer from "@next/bundle-analyzer";
import createMdxPlugin from "@next/mdx";
import createSvgPlugin from "@stefanprobst/next-svg";
import withFrontmatter from "remark-frontmatter";
import withGfm from "remark-gfm";
import withMdxFrontmatter from "remark-mdx-frontmatter";
const isProductionDeploy = process.env["NEXT_PUBLIC_BASE_URL"]?.startsWith(
"https://campus.dariah.eu",
);
/** @type {NextConfig} */
const config = {
eslint: {
dirs: ["."],
ignoreDuringBuilds: true,
},
experimental: {
outputFileTracingExcludes: {
/**
* Next.js standalone output incorrectly includes the content folder,
* which will lead to deployment error:
* "Max serverless function size of 50 MB compressed or 250 MB uncompressed reached"
*/
"**/*": ["./content/**/*", "node_modules/**/@swc/core*"],
},
},
async headers() {
const headers = [];
if (isProductionDeploy !== true) {
headers.push({
source: "/:path*",
headers: [
{
key: "X-Robots-Tag",
value: "noindex, nofollow",
},
],
});
console.warn("⚠️ Indexing by search engines is disallowed.");
}
return headers;
},
i18n: {
locales: ["en"],
defaultLocale: "en",
},
output: "standalone",
pageExtensions: ["page.tsx", "page.mdx", "api.ts"],
poweredByHeader: false,
async redirects() {
return [
/**
* Permanent redirects for renamed resources.
* Should include full uri-encoded pathname, without base url.
*
* @example
* ```json
* {
* "/resource/posts/old-resource": "/resource/posts/new-resource"
* }
*
*/
...Object.entries(
JSON.parse(await readFile(join(process.cwd(), "./redirects.json"), { encoding: "utf-8" })),
).map(([source, destination]) => {
return {
source,
destination,
permanent: true,
};
}),
/**
* Auto-generated redirects for uuids.
*/
...Object.entries(
JSON.parse(
await readFile(join(process.cwd(), "./redirects.resources.json"), { encoding: "utf-8" }),
),
).map(([uuid, id]) => {
return {
source: `/id/${uuid}`,
destination: `/resource/posts/${id}`,
permanent: false,
};
}),
...Object.entries(
JSON.parse(
await readFile(join(process.cwd(), "./redirects.courses.json"), { encoding: "utf-8" }),
),
).map(([uuid, id]) => {
return {
source: `/id/${uuid}`,
destination: `/curriculum/${id}`,
permanent: false,
};
}),
...Object.entries(
JSON.parse(
await readFile(join(process.cwd(), "./redirects.events.json"), { encoding: "utf-8" }),
),
).map(([uuid, id]) => {
return {
source: `/id/${uuid}`,
destination: `/resource/events/${id}`,
permanent: false,
};
}),
/**
* Redirects for legacy resources from previous iteration of dariah-campus.
*/
// ...Object.entries(
// JSON.parse(
// await readFile(join(process.cwd(), "./redirects.legacy.resources.json"), {
// encoding: "utf-8",
// }),
// ),
// ).map(([legacyId, id]) => {
// return {
// source: `/resource/${legacyId}`,
// destination: `/resource/posts/${id}`,
// permanent: true,
// };
// }),
// ...Object.entries(
// JSON.parse(
// await readFile(join(process.cwd(), "./redirects.legacy.events.json"), {
// encoding: "utf-8",
// }),
// ),
// ).map(([legacyId, id]) => {
// return {
// source: `/resource/${legacyId}`,
// destination: `/resource/events/${id}`,
// permanent: true,
// };
// }),
// ...Object.entries(
// JSON.parse(
// await readFile(join(process.cwd(), "./redirects.legacy.persons.json"), {
// encoding: "utf-8",
// }),
// ),
// ).map(([legacyId, id]) => {
// return {
// source: `/author/${legacyId}`,
// destination: `/author/${id}`,
// permanent: true,
// };
// }),
];
},
async rewrites() {
return [
{ source: "/resources", destination: "/resources/page/1" },
{ source: "/resources/:type", destination: "/resources/:type/page/1" },
{ source: "/courses", destination: "/courses/page/1" },
{ source: "/authors", destination: "/authors/page/1" },
{ source: "/author/:id", destination: "/author/:id/page/1" },
{ source: "/tags", destination: "/tags/page/1" },
{ source: "/tag/:id", destination: "/tag/:id/page/1" },
{ source: "/categories", destination: "/categories/page/1" },
{ source: "/category/:id", destination: "/category/:id/page/1" },
{ source: "/about", destination: "/docs/about" },
];
},
typescript: {
ignoreBuildErrors: true,
},
};
/** @type {Array<(config: NextConfig) => NextConfig>} */
const plugins = [
createBundleAnalyzer({ enabled: process.env.BUNDLE_ANALYZER === "enabled" }),
createMdxPlugin({
extension: /\.mdx?/,
options: {
remarkPlugins: [withFrontmatter, withMdxFrontmatter, withGfm],
},
}),
createSvgPlugin({}),
];
export default plugins.reduce((config, plugin) => {
return plugin(config);
}, config);