Append new rules to existing .htaccess file instead of overwriting it.
This commit is contained in:
parent
5ac64c5db6
commit
4b56fd20ae
2 changed files with 16 additions and 1 deletions
13
CHANGELOG.md
Normal file
13
CHANGELOG.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
Append new rules to existing `.htaccess` file instead of overwriting it.
|
||||||
|
|
||||||
|
## 0.1.2
|
||||||
|
|
||||||
|
Fix redirects by checking the `redirect` field.
|
||||||
|
|
||||||
|
## 0.1.1
|
||||||
|
|
||||||
|
Initial release.
|
|
@ -1,4 +1,5 @@
|
||||||
import type { AstroIntegration } from "astro";
|
import type { AstroIntegration } from "astro";
|
||||||
|
import { existsSync } from "node:fs";
|
||||||
import { writeFile } from "node:fs/promises";
|
import { writeFile } from "node:fs/promises";
|
||||||
import path, { posix as pathPosix } from "node:path";
|
import path, { posix as pathPosix } from "node:path";
|
||||||
import { fileURLToPath, URL } from "node:url";
|
import { fileURLToPath, URL } from "node:url";
|
||||||
|
@ -176,7 +177,8 @@ export const integration = ({ generateHtaccessFile, errorPages, redirects, custo
|
||||||
.map((fn) => fn())
|
.map((fn) => fn())
|
||||||
.flat();
|
.flat();
|
||||||
if (!error) {
|
if (!error) {
|
||||||
await writeFile(path.join(assetsDir, ".htaccess"), htaccess.join("\n"));
|
const htaccessPath = path.join(assetsDir, ".htaccess");
|
||||||
|
await writeFile(htaccessPath, [existsSync(htaccessPath) ? "\n" : "", htaccess.join("\n")], { flag: 'a' });
|
||||||
logger.info(`Generated .htaccess with ${htaccess.length} ${htaccess.length === 1 ? "rule" : "rules"}`);
|
logger.info(`Generated .htaccess with ${htaccess.length} ${htaccess.length === 1 ? "rule" : "rules"}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue