web: add automatic sitemap generation

This commit is contained in:
jj
2024-12-10 16:14:15 +00:00
parent e041e376c7
commit f1916cef6e
3 changed files with 105 additions and 1 deletions

View File

@@ -47,6 +47,7 @@
"svelte": "^4.2.19",
"svelte-check": "^3.6.0",
"svelte-preprocess": "^6.0.2",
"svelte-sitemap": "2.6.0",
"sveltekit-i18n": "^2.4.2",
"ts-deepmerge": "^7.0.1",
"tslib": "^2.4.1",

View File

@@ -3,6 +3,7 @@ import { sveltekit } from "@sveltejs/kit/vite";
import basicSSL from "@vitejs/plugin-basic-ssl";
import { glob } from "glob";
import mime from "mime";
import { createSitemap } from 'svelte-sitemap/src/index'
import { cp, readdir, mkdir } from "node:fs/promises";
import { createReadStream } from "node:fs";
@@ -60,12 +61,28 @@ const enableCOEP: PluginOption = {
}
};
const generateSitemap: PluginOption = {
name: "generate-sitemap",
async writeBundle(bundle) {
if (!process.env.WEB_HOST || !bundle.dir?.endsWith('server')) {
return;
}
await createSitemap(`https://${process.env.WEB_HOST}`, {
changeFreq: 'monthly',
outDir: '.svelte-kit/output/prerendered/pages',
resetTime: true
});
}
}
export default defineConfig({
plugins: [
basicSSL(),
sveltekit(),
enableCOEP,
exposeLibAV
exposeLibAV,
generateSitemap
],
build: {
rollupOptions: {