aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-09-14 18:12:53 +0200
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-09-14 18:12:53 +0200
commit75c9e412287ace0801d752ce731824243d7c8b53 (patch)
tree3e0361f64f277ef3978725a9fdf4b8632c231ca0 /src/lib
parent53e3544effa012d36f3b0d732a922ca219b7692a (diff)
downloadfahrplan-75c9e412287ace0801d752ce731824243d7c8b53.tar.gz
fahrplan-75c9e412287ace0801d752ce731824243d7c8b53.tar.bz2
fahrplan-75c9e412287ace0801d752ce731824243d7c8b53.tar.lz
fahrplan-75c9e412287ace0801d752ce731824243d7c8b53.zip

feat: small changes

Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Timetable.svelte8
-rw-r--r--src/lib/aliases.ts26
-rw-r--r--src/lib/motis-api.ts10
3 files changed, 36 insertions, 8 deletions
diff --git a/src/lib/Timetable.svelte b/src/lib/Timetable.svelte
index c805d6d..f6f4a4e 100644
--- a/src/lib/Timetable.svelte
+++ b/src/lib/Timetable.svelte
@@ -2,7 +2,7 @@
import { browser, building, dev } from '$app/environment';
import { page } from '$app/state';
import { S } from '$lib';
- import { operators } from './aliases';
+ import { normalisePlaceName, operators } from './aliases';
import LineGlyph from './assets/LineGlyph.svelte';
import Pictogram from './assets/Pictogram.svelte';
import { Mode, type StoptimesResponse } from './motis-types';
@@ -284,7 +284,9 @@
<span class="ml-1 -mr-0.5 md:mt-0.5 font-sbb-typo">
<!-- {isArrivals ? m.from() : m.to()} -->
{m.to()}
- <span class="font-semibold">{departure.headsign}</span>
+ <span class="font-semibold"
+ >{normalisePlaceName(departure.headsign)}</span
+ >
</span>
</div>
<div class="flex-1"></div>
@@ -378,7 +380,7 @@
<h2 class="text-2xl opacity-90">{m.no_results_title()}</h2>
<p>
{#each m
- .no_results_body({ stationName })
+ .no_results_body({ stationName: placeName ?? placeId })
.split('*') as part, idx}{#if idx % 2 === 0}{part}{:else}<b
>{part}</b
>{/if}{/each}
diff --git a/src/lib/aliases.ts b/src/lib/aliases.ts
index c954f56..7308315 100644
--- a/src/lib/aliases.ts
+++ b/src/lib/aliases.ts
@@ -1,5 +1,6 @@
import { m } from './paraglide/messages';
+// #region Stations
export const placeNameMap = new Map<string, string>();
for (const [v1, v2] of [
['Freiburg(Brsg)', 'Freiburg(Breisgau) Hbf'],
@@ -15,8 +16,32 @@ for (const [v1, v2] of [
['Freiburg Hauptbahnhof', 'Freiburg(Breisgau) Hbf'],
['S+U Berlin Hauptbahnhof', 'Berlin Hbf'],
['Berlin Hauptbahnhof', 'Berlin Hbf'],
+ ['Hauptbahnhof (oben)', 'Stuttgart Hbf (oben)'], // probably
+ ['de-DELFI_de:08111:6115:1:1', 'Stuttgart Hbf (oben)'],
])
placeNameMap.set(v1.toLowerCase(), v2);
+
+export const normaliseGermanUmlauts = (n: string) => {
+ return n
+ .replace(/ü/gu, 'ue')
+ .replace(/Ü/gu, 'UE')
+ .replace(/ä/gu, 'ae')
+ .replace(/Ä/gu, 'AE')
+ .replace(/ö/gu, 'oe')
+ .replace(/ß/gu, 'ss');
+};
+export const normalisePlaceName = (name: string, id?: string) =>
+ placeNameMap.has(name.toLowerCase())
+ ? placeNameMap.get(name.toLowerCase())!
+ : id && placeNameMap.has(id)
+ ? placeNameMap.get(id)!
+ : name;
+export const arePlacenamesEqual = (n1: string, n2: string) =>
+ normalisePlaceName(normaliseGermanUmlauts(n1).toUpperCase()).toUpperCase() ===
+ normalisePlaceName(normaliseGermanUmlauts(n2)).toUpperCase();
+// #endregion
+
+// #region Operators
export const operators = new Map<string, string>();
operators.set('Schweizerische Bundesbahnen SBB', m.operator_sbb());
operators.set('SBB', m.operator_sbb());
@@ -37,3 +62,4 @@ operators.set('Verkehrsbetriebe Glattal', m.operator_vbg());
operators.set('OEBB Personenverkehr AG Kundenservice', m.operator_oebb());
operators.set('Österreichische Bundesbahnen', m.operator_oebb());
+// #endregion
diff --git a/src/lib/motis-api.ts b/src/lib/motis-api.ts
index 347c20a..7933c39 100644
--- a/src/lib/motis-api.ts
+++ b/src/lib/motis-api.ts
@@ -1,7 +1,7 @@
import type { StoptimesResponse } from './motis-types';
export class MotisAPI {
- backend = 'https://api.transitous.org';
- fetch: typeof fetch = (url, init) =>
+ public backend = 'https://api.transitous.org';
+ public fetch: typeof fetch = (url, init) =>
fetch(
`${this.backend}${this.backend.endsWith('/') ? '' : '/'}${
typeof url === 'string'
@@ -14,8 +14,8 @@ export class MotisAPI {
}`,
init
);
- async getStopTimes(
- id: string,
+ public async getStationTimetable(
+ stationId: string,
abortSignal?: AbortSignal,
arrivals = false,
limit = 128,
@@ -25,7 +25,7 @@ export class MotisAPI {
) {
const res = await this.fetch(
`/api/v1/stoptimes?stopId=${encodeURIComponent(
- id
+ stationId
)}&n=${encodeURIComponent(limit.toString())}&arriveBy=${
arrivals ? 'true' : 'false'
}&withScheduledSkippedStops=${