pregenerate location names and fix location forwarding
This commit is contained in:
@@ -2,7 +2,10 @@ import { error, redirect } from '@sveltejs/kit';
|
||||
|
||||
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 {
|
||||
const locationRoute = geoLocationNameToRoute(location.name);
|
||||
@@ -61,6 +64,8 @@ export async function resolveLocationFromRoute({
|
||||
const split = urlLocation.split('_');
|
||||
urlLocationName = split[0];
|
||||
urlLocationId = split[1];
|
||||
} else if (urlLocation.includes('-')) {
|
||||
urlLocationName = urlLocation.replace(/-/g, ' ');
|
||||
} else if (/^\d+$/.test(urlLocation)) {
|
||||
urlLocationName = '';
|
||||
urlLocationId = urlLocation;
|
||||
|
||||
Reference in New Issue
Block a user