pregenerate location names and fix location forwarding

This commit is contained in:
terraputix
2026-02-20 23:08:04 +01:00
parent bed6e3aa53
commit 65fe6d1601
5 changed files with 33 additions and 14 deletions
+23 -2
View File
@@ -1,13 +1,34 @@
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import fs from 'fs';
import path from 'path';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: { adapter: adapter() }
kit: {
adapter: adapter(),
// Pregenerate city pages to improve SEO during static build
prerender: {
entries: (() => {
try {
const citiesPath = path.resolve('src/routes/weather/locations/city-names100.json');
const raw = fs.readFileSync(citiesPath, 'utf-8');
const cities = JSON.parse(raw);
if (Array.isArray(cities)) {
const cityEntries = cities.map((c) => `/weather/week/${c}`);
// Keep the default wildcard to include other routes
return ['*', ...cityEntries];
}
} catch {
// If anything goes wrong, fall back to default behavior
}
return ['*'];
})()
}
}
};
export default config;