pregenerate location names and fix location forwarding
This commit is contained in:
+23
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user