forked from renatorib/renatorib.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
68 lines (57 loc) · 1.59 KB
/
Copy pathnext.config.js
File metadata and controls
68 lines (57 loc) · 1.59 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
const fs = require("fs");
const { join } = require("path");
const withPlugins = require("next-compose-plugins");
const withOptimizedImages = require("next-optimized-images");
const nextMDX = require("@zeit/next-mdx");
const { getPosts } = require("./scripts/get-posts");
const plugins = [
withOptimizedImages,
nextMDX({
extension: /\.(md|mdx)$/
})
];
const config = {
pageExtensions: ["js", "jsx", "mdx"],
exportPathMap: async function(defaultPathMap, { dev, dir, outDir }) {
const STATIC_ROOT_FILES = ["CNAME", ".nojekyll"];
if (!dev) {
// copy static root files
STATIC_ROOT_FILES.forEach(file =>
fs.copyFileSync(join(dir, file), join(outDir, file))
);
fs.writeFileSync(
join(outDir, "README.md"),
"The `master` branch contains build source for gh-pages." +
"If you're looking for source code, switch to `src` branch"
);
}
delete defaultPathMap["/blog/[slug]"];
const postsPathMap = getPosts().reduce(
(acc, post) => ({
...acc,
[`/blog/${post.slug}`]: {
page: "/blog/[slug]",
query: { slug: post.slug }
}
}),
{}
);
const tagsPathMap = ["tutorial", "javascript", "react"].reduce(
(acc, tagName) => ({
...acc,
[`/blog/tag/${tagName}`]: {
page: "/blog/tag/[slug]",
query: { slug: tagName }
}
}),
{}
);
return {
...defaultPathMap,
...postsPathMap,
...tagsPathMap,
"/404.html": { page: "/_error" }
};
}
};
module.exports = withPlugins(plugins, config);