-
Notifications
You must be signed in to change notification settings - Fork 3
/
temp-sitemap-fix.ts
33 lines (32 loc) · 1.22 KB
/
temp-sitemap-fix.ts
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
import type { AstroIntegration } from "astro";
import { cp, readdir } from "node:fs/promises";
import * as path from "node:path";
// TODO: temporary fix: https://github.com/withastro/adapters/issues/445#issuecomment-2526327882
export function sitemapFix(): AstroIntegration {
return {
name: "sitemap-fix",
hooks: {
"astro:build:done": async ({ logger }) => {
const buildLogger = logger.fork("sitemap-fix");
buildLogger.info("Copying xml files from dist to vercel out");
try {
const files = await readdir("./dist/client");
const xmlFiles = files.filter(
(file) =>
path.extname(file).toLowerCase() === ".xml" &&
path.basename(file).toLowerCase().startsWith("sitemap")
);
buildLogger.info(xmlFiles.join(", "));
for (const file of xmlFiles) {
const sourcePath = path.join("./dist/client", file);
const destPath = path.join("./.vercel/output/static", file);
await cp(sourcePath, destPath);
}
buildLogger.info("All XML files copied successfully");
} catch (error) {
buildLogger.error(`Error copying files: ${error}`);
}
},
},
};
}