Skip to content

Commit

Permalink
Add sitemap copier integration as workaround solution
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasbekkevold committed Jan 5, 2025
1 parent f620fe1 commit f15f936
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import remarkCollapse from "remark-collapse";
import sitemap from "@astrojs/sitemap";
import { SITE } from "./src/config";
import { remarkReadingTime } from "./src/utils/remark-reading-time.mjs";
import { sitemapCopier } from "./src/utils/sitemap-copier.ts";

import vercel from "@astrojs/vercel";

Expand All @@ -19,6 +20,7 @@ export default defineConfig({
}),
react(),
sitemap(),
sitemapCopier(),
],

markdown: {
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Site, SocialObjects } from "./types";

export const SITE: Site = {
website: "https://nicklasbekkevold.com/",
website: "https://nicklasbekkevold.com",
author: "Nicklas Bekkevold",
profile: "https://nicklasbekkevold.com/",
profile: "https://nicklasbekkevold.com",
desc: "Independent internet magazine featuring thoughts and reflections at the intersection of science, technology, and society.",
title: "nicklasbekkevold.com",
ogImage: "astropaper-og.jpg",
Expand Down
32 changes: 32 additions & 0 deletions src/utils/sitemap-copier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { AstroIntegration } from "astro";
import { readdir, cp } from "node:fs/promises";
import * as path from "node:path";

export function sitemapCopier(): AstroIntegration {
return {
name: "sitemap-copier",
hooks: {
"astro:build:done": async ({ logger }) => {
const buildLogger = logger.fork("sitemap-copier");
buildLogger.info("Copying xml files from dist to vercel out");
try {
const files = await readdir("./dist");
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", 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}`);
}
},
},
};
}

0 comments on commit f15f936

Please sign in to comment.