pregenerate location names and fix location forwarding
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
export * from './ui.ts';
|
export * from './ui.ts';
|
||||||
export * from './meteo.ts';
|
|
||||||
|
|
||||||
export const pad = (n: string | number) => {
|
export const pad = (n: string | number) => {
|
||||||
if (n === null || n === undefined) {
|
if (n === null || n === undefined) {
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import { error, redirect } from '@sveltejs/kit';
|
|||||||
|
|
||||||
import { type GeoLocation, storedLocation } from '$lib/stores/settings';
|
import { type GeoLocation, storedLocation } from '$lib/stores/settings';
|
||||||
|
|
||||||
import { geoLocationNameToRoute } from '$lib/utils/meteo';
|
export const geoLocationNameToRoute = (name: string) => {
|
||||||
|
const lowerCase = name.toLowerCase().replaceAll(' ', '-');
|
||||||
|
return lowerCase.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
export function buildLocationRoute(location: GeoLocation): string {
|
export function buildLocationRoute(location: GeoLocation): string {
|
||||||
const locationRoute = geoLocationNameToRoute(location.name);
|
const locationRoute = geoLocationNameToRoute(location.name);
|
||||||
@@ -61,6 +64,8 @@ export async function resolveLocationFromRoute({
|
|||||||
const split = urlLocation.split('_');
|
const split = urlLocation.split('_');
|
||||||
urlLocationName = split[0];
|
urlLocationName = split[0];
|
||||||
urlLocationId = split[1];
|
urlLocationId = split[1];
|
||||||
|
} else if (urlLocation.includes('-')) {
|
||||||
|
urlLocationName = urlLocation.replace(/-/g, ' ');
|
||||||
} else if (/^\d+$/.test(urlLocation)) {
|
} else if (/^\d+$/.test(urlLocation)) {
|
||||||
urlLocationName = '';
|
urlLocationName = '';
|
||||||
urlLocationId = urlLocation;
|
urlLocationId = urlLocation;
|
||||||
|
|||||||
@@ -1,7 +1 @@
|
|||||||
export function geoLocationNameToRoute(name: string): string {
|
|
||||||
// Placeholder implementation
|
|
||||||
return name
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/[^a-z0-9]+/g, '-')
|
|
||||||
.replace(/^-*|-*$/g, '');
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
>
|
>
|
||||||
Model
|
Model
|
||||||
</th>
|
</th>
|
||||||
{#each filteredIndices as idx, i}
|
{#each filteredIndices as idx, i (idx)}
|
||||||
{@const ts = timestamps[idx]}
|
{@const ts = timestamps[idx]}
|
||||||
{@const isNewDay = checkNewDay(i, ts)}
|
{@const isNewDay = checkNewDay(i, ts)}
|
||||||
<th
|
<th
|
||||||
@@ -115,14 +115,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each displayModels as model}
|
{#each displayModels as model (model)}
|
||||||
<tr class="group hover:bg-muted/10">
|
<tr class="group hover:bg-muted/10">
|
||||||
<td
|
<td
|
||||||
class="sticky left-0 z-10 border-b border-r border-border bg-card p-2 text-[11px] font-semibold group-hover:bg-muted/20"
|
class="sticky left-0 z-10 border-b border-r border-border bg-card p-2 text-[11px] font-semibold group-hover:bg-muted/20"
|
||||||
>
|
>
|
||||||
{model.replace(/_/g, ' ')}
|
{model.replace(/_/g, ' ')}
|
||||||
</td>
|
</td>
|
||||||
{#each filteredIndices as idx, i}
|
{#each filteredIndices as idx, i (idx)}
|
||||||
{@const ts = timestamps[idx]}
|
{@const ts = timestamps[idx]}
|
||||||
{@const codes = hourlyFlat[`weather_code_${model}`]}
|
{@const codes = hourlyFlat[`weather_code_${model}`]}
|
||||||
{@const code = codes ? codes[idx] : 0}
|
{@const code = codes ? codes[idx] : 0}
|
||||||
|
|||||||
+23
-2
@@ -1,13 +1,34 @@
|
|||||||
import adapter from '@sveltejs/adapter-static';
|
import adapter from '@sveltejs/adapter-static';
|
||||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
// Consult https://svelte.dev/docs/kit/integrations
|
// Consult https://svelte.dev/docs/kit/integrations
|
||||||
// for more information about preprocessors
|
// for more information about preprocessors
|
||||||
preprocess: vitePreprocess(),
|
preprocess: vitePreprocess(),
|
||||||
|
kit: {
|
||||||
kit: { adapter: adapter() }
|
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;
|
export default config;
|
||||||
|
|||||||
Reference in New Issue
Block a user