aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--messages/de-ch.json2
-rw-r--r--src/lib/Timetable.svelte8
-rw-r--r--src/lib/aliases.ts26
-rw-r--r--src/lib/motis-api.ts10
-rw-r--r--src/routes/(app)/fahrplan/+page.svelte30
-rw-r--r--src/routes/(app)/fahrplan/route/[id]/+page.svelte1
6 files changed, 48 insertions, 29 deletions
diff --git a/messages/de-ch.json b/messages/de-ch.json
index 4133d58..6b49062 100644
--- a/messages/de-ch.json
+++ b/messages/de-ch.json
@@ -99,7 +99,7 @@
"declarations": ["input stationName"],
"selectors": ["stationName"],
"match": {
- "*": "Es wurden keine Ergebnisse für den Sender *{stationName}* gefunden.\nBitte versuchen Sie es erneut."
+ "*": "Es wurden keine Ergebnisse für den Bahnhof *{stationName}* gefunden.\nBitte versuchen Sie es erneut."
}
}
],
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=${
diff --git a/src/routes/(app)/fahrplan/+page.svelte b/src/routes/(app)/fahrplan/+page.svelte
index 336c7bb..7584530 100644
--- a/src/routes/(app)/fahrplan/+page.svelte
+++ b/src/routes/(app)/fahrplan/+page.svelte
@@ -10,24 +10,11 @@
import { page } from '$app/state';
import { m } from '$lib/paraglide/messages';
import motis from '$lib/motis-api';
- import { placeNameMap } from '$lib/aliases';
-
- const normaliseGermanUmlauts = (n: string) => {
- return n
- .replace(/ü/gu, 'ue')
- .replace(/Ü/gu, 'UE')
- .replace(/ä/gu, 'ae')
- .replace(/Ä/gu, 'AE')
- .replace(/ö/gu, 'oe')
- .replace(/ß/gu, 'ss');
- };
- const normalisePlaceName = (n: string) =>
- placeNameMap.has(n.toLowerCase()) ? placeNameMap.get(n.toLowerCase())! : n;
- const arePlacenamesEqual = (n1: string, n2: string) =>
- normalisePlaceName(
- normaliseGermanUmlauts(n1).toUpperCase()
- ).toUpperCase() ===
- normalisePlaceName(normaliseGermanUmlauts(n2)).toUpperCase();
+ import {
+ arePlacenamesEqual,
+ normalisePlaceName,
+ placeNameMap,
+ } from '$lib/aliases';
let searchQuery = $state('');
let searchSuggestionIdx = $state(0);
@@ -107,7 +94,10 @@
let stopTimes = $state(null as null | StoptimesResponse);
let hasQueriedResults = $state(false);
let renderedObjectIdName = $derived(
- normalisePlaceName(objectIdName || (stopTimes?.place?.name ?? ''))
+ normalisePlaceName(
+ objectIdName || (stopTimes?.place?.name ?? ''),
+ objectId ?? undefined
+ )
);
const search = async (query: string) => {
@@ -190,7 +180,7 @@
progressKind = 'fetch';
try {
resultsLoopCancel = new AbortController();
- const json = await motis.getStopTimes(
+ const json = await motis.getStationTimetable(
objectId,
resultsLoopCancel.signal,
isArrivals
diff --git a/src/routes/(app)/fahrplan/route/[id]/+page.svelte b/src/routes/(app)/fahrplan/route/[id]/+page.svelte
new file mode 100644
index 0000000..5bf03f4
--- /dev/null
+++ b/src/routes/(app)/fahrplan/route/[id]/+page.svelte
@@ -0,0 +1 @@
+<script lang="ts"></script>