import { defineConfig } from "astro/config";
import sitemap from "@astrojs/sitemap";
import node from "@astrojs/node";
import path from "node:path";

const customOutDir = process.env.QIYOUXUE_BUILD_OUT_DIR;

export default defineConfig({
  site: "https://qiyouxueedu.com",
  integrations: [sitemap({
    filter: (page) => {
      const pathname = new URL(page).pathname;
      return pathname !== "/404/"
        && pathname !== "/admin/"
        && !pathname.startsWith("/api/")
        && !pathname.startsWith("/uploads/")
        && !pathname.endsWith(".txt");
    },
  })],
  adapter: node({ mode: "standalone" }),
  ...(customOutDir ? { outDir: path.resolve(customOutDir) } : {}),
  build: { format: "directory" },
  trailingSlash: "ignore",
});
