forked from jdanyow/docs-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirects.mjs
More file actions
25 lines (22 loc) · 715 Bytes
/
Copy pathredirects.mjs
File metadata and controls
25 lines (22 loc) · 715 Bytes
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
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
const json = readFileSync(join(process.cwd(), "vercel.json"), "utf8");
const data = JSON.parse(json);
let redirects = {};
data.redirects.forEach((redirect) => {
let source = redirect.source;
if (source.endsWith("/")) {
source = source.slice(0, -1);
}
redirects[source] = redirect.destination;
});
let newRedirects = [];
Object.entries(redirects).forEach(([source, destination]) => {
newRedirects.push({
source: `${source}{/}?`,
destination,
permanent: true,
});
});
const outJson = JSON.stringify({ redirects: newRedirects }, null, 2);
writeFileSync(join(process.cwd(), "vercel.json"), outJson, "utf-8");