Skip to content

Commit

Permalink
Properly revert page routes after building
Browse files Browse the repository at this point in the history
  • Loading branch information
xbubbo committed Nov 10, 2024
1 parent 7e7ed69 commit ce1dd6a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function RandomizeNames() {
fs.writeFileSync(astroFile, fileContent, "utf-8");
}
}

function FindAstroFiles(dir: string): string[] {
let results: string[] = [];
const list = fs.readdirSync(dir);
Expand All @@ -65,6 +66,18 @@ function Revert() {
path.join(pagesDir, `${oldPath.replace("/", "")}.astro`),
);
}

const AstroFiles = FindAstroFiles(process.cwd());
for (const astroFile of AstroFiles) {
let fileContent = fs.readFileSync(astroFile, "utf-8");

for (const [oldName, newName] of Object.entries(RenamedFiles)) {
const regex = new RegExp(`"${newName}"`, "g");
fileContent = fileContent.replace(regex, `"${oldName}"`);
}

fs.writeFileSync(astroFile, fileContent, "utf-8");
}
}

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

0 comments on commit ce1dd6a

Please sign in to comment.