-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnext.config.js
38 lines (30 loc) · 888 Bytes
/
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
const fs = require("fs");
const { join } = require("path");
const matter = require("gray-matter");
const postsDirectory = join(process.cwd(), "public/posts");
module.exports = {
async redirects() {
const redirects = [];
for (let slug of fs.readdirSync(postsDirectory)) {
const postDir = join(postsDirectory, slug);
const absPostPath = join(postDir, `post.md`);
const fileContents = fs.readFileSync(absPostPath, "utf8");
const { data, content } = matter(fileContents);
if (!data.oldUrl) continue;
redirects.push({
source: data.oldUrl,
destination: `/posts/${slug}`,
permanent: true,
});
}
return redirects;
},
async rewrites() {
return [
{
source: "/wp-content/:splat*",
destination: "http://d18l99bmg6trdn.cloudfront.net/wp-content/:splat*",
},
];
},
};