-
Notifications
You must be signed in to change notification settings - Fork 449
/
next.config.js
141 lines (131 loc) · 3.42 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
const path = require("path");
const { globSync } = require("glob");
const compareVersions = require("compare-versions");
module.exports = {
webpack: (config, options) => {
config.module.rules.push({
test: /\.mjs/,
include: /node_modules/,
type: "javascript/auto",
});
return config;
},
// Next.js config
async redirects() {
return [
{
source: "/case-studies/:slug*",
destination: "/primitives/case-studies/:slug*",
permanent: true,
},
{
source: "/colors/docs",
destination: "/colors/docs/overview/installation",
permanent: true,
},
{
source: "/colors/docs/tests/:slug*",
destination: "/colors",
permanent: true,
},
{
source: "/docs/colors/palette-composition/the-scales",
destination: "/colors/docs/palette-composition/scales",
permanent: true,
},
{
source: "/docs/colors/getting-started/:slug*",
destination: "/colors/docs/overview/:slug*",
permanent: true,
},
{
source: "/docs/colors/:slug*",
destination: "/colors/docs/:slug*",
permanent: true,
},
{
source: "/docs/primitives",
destination: "/primitives/docs/overview/introduction",
permanent: false,
},
{
source: "/docs/primitives/utilities/aspect-ratio/:slug*",
destination: "/primitives/docs/components/aspect-ratio/:slug*",
permanent: true,
},
{
source: "/docs/primitives/utilities/label/:slug*",
destination: "/primitives/docs/components/label/:slug*",
permanent: true,
},
{
source: "/docs/primitives/:slug*",
destination: "/primitives/docs/:slug*",
permanent: true,
},
{
source: "/primitives/docs",
destination: "/primitives/docs/overview/introduction",
permanent: false,
},
{
source: "/themes",
destination: "/",
permanent: false,
},
{
source: "/themes/docs",
destination: "/themes/docs/overview/getting-started",
permanent: false,
},
];
},
// Generate URL rewrites for components and utilities
// So navigating to /tooltip rewrites to /tooltip/[latestVersion]
async rewrites() {
const DATA_PATH = path.join(__dirname, "data");
function getLatestVersionFromPath(fromPath) {
const paths = globSync(`${DATA_PATH}/${fromPath}/**/*.mdx`);
const components = {};
paths.forEach((p) => {
const [name, version] = p
.replace(DATA_PATH, "")
.replace(`/${fromPath}/`, "")
.replace(".mdx", "")
.split("/");
components[name] = [...(components[name] || [version]), version];
});
const latest = Object.entries(components).reduce((acc, curr) => {
const [name, versions] = curr;
const [latestVersion] = versions.sort(compareVersions).reverse();
acc[name] = latestVersion;
return acc;
}, {});
return latest;
}
function createRewrites(latestVersionMap, url) {
return [...Object.entries(latestVersionMap)].reduce((redirects, curr) => {
const [name, version] = curr;
redirects.push({
source: `${url}${name}`,
destination: `${url}${name}/${version}`,
});
return redirects;
}, []);
}
return [
...createRewrites(
getLatestVersionFromPath("primitives/docs/components"),
"/primitives/docs/components/",
),
...createRewrites(
getLatestVersionFromPath("primitives/docs/utilities"),
"/primitives/docs/utilities/",
),
...createRewrites(
getLatestVersionFromPath("design-system/docs/components"),
"/design-docs/system/components/",
),
];
},
};