Skip to content

Commit ce1dd6a

Browse files
committed
Properly revert page routes after building
1 parent 7e7ed69 commit ce1dd6a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function RandomizeNames() {
3939
fs.writeFileSync(astroFile, fileContent, "utf-8");
4040
}
4141
}
42+
4243
function FindAstroFiles(dir: string): string[] {
4344
let results: string[] = [];
4445
const list = fs.readdirSync(dir);
@@ -65,6 +66,18 @@ function Revert() {
6566
path.join(pagesDir, `${oldPath.replace("/", "")}.astro`),
6667
);
6768
}
69+
70+
const AstroFiles = FindAstroFiles(process.cwd());
71+
for (const astroFile of AstroFiles) {
72+
let fileContent = fs.readFileSync(astroFile, "utf-8");
73+
74+
for (const [oldName, newName] of Object.entries(RenamedFiles)) {
75+
const regex = new RegExp(`"${newName}"`, "g");
76+
fileContent = fileContent.replace(regex, `"${oldName}"`);
77+
}
78+
79+
fs.writeFileSync(astroFile, fileContent, "utf-8");
80+
}
6881
}
6982

7083
const port = Number.parseInt(process.env.PORT as string) || inConfig.port || 8080;

0 commit comments

Comments
 (0)