@autobusal/routes-search 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.3 (2026-08-29)
4
+
5
+ - A city with a single station lists that station instead of an identical "All Stations" entry beside it; the submitted value stays the city's slug, so URLs are unchanged.
6
+
3
7
  ## 1.2.0
4
8
 
5
9
  **The date picker follows the departure city.** Choosing a "from" city now sets the picker's floor to that city's timezone, and a pre-filled form (a shared link, or the search form kept on the results page) sets it on mount rather than waiting for a keystroke.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/routes-search",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"
package/utilities.ts CHANGED
@@ -6,15 +6,69 @@ export const getCities = (cities: CityData[], t: TFunction<'common'>): Autocompl
6
6
  const data: AutocompleteData[] = [];
7
7
 
8
8
  cities.forEach(city => {
9
+ /*
10
+ * Claude - Date: 2026-08-21
11
+ *
12
+ * Every spelling this place answers to, so the box matches what the
13
+ * visitor TYPES rather than what their interface language happens to
14
+ * call the place. `aliases` comes from /api/cities/browse and holds the
15
+ * name in all 15 languages plus historical and colloquial variants -
16
+ * "Solun", "Selanik", "Θεσσαλονίκη" and "Salonic" all reach
17
+ * Thessaloniki. The country name and the slug go in too: the slug is
18
+ * what appears in the URL, so somebody pasting or half-remembering one
19
+ * finds the city.
20
+ *
21
+ * These are NEVER displayed - `name` is what shows, resolved to the
22
+ * visitor's own language server-side.
23
+ */
24
+ const search = [
25
+ ...(city.aliases ?? []),
26
+ city.country?.name ?? '',
27
+ city.slug
28
+ ].filter(Boolean);
29
+
30
+ const stops = city.stops ?? [];
31
+
32
+ /*
33
+ * Edited: Claude - Date: 2026-08-29
34
+ *
35
+ * A CITY WITH ONE STATION OFFERS NO CHOICE. Listing both "(All
36
+ * Stations)" and the station itself puts two entries in the box for
37
+ * one place, and the visitor has to read both to discover they are the
38
+ * same - so the station is named and the pair collapses to a single
39
+ * line.
40
+ *
41
+ * The value stays the CITY's, not the station's: with one station the
42
+ * search is identical either way, and keeping the city slug keeps the
43
+ * URL (and everything keyed off it - canonicals, the prerendered pair
44
+ * pages, the date strip) exactly as it is. The day a second station
45
+ * appears, this reverts to "All Stations" plus one entry each, on its
46
+ * own.
47
+ */
48
+ if (stops.length === 1) {
49
+ data.push({
50
+ name: `${ city.name }, ${ city.country?.name ?? '' } (${ stops[0].name })`,
51
+ value: `${ city.slug }`,
52
+ search: [ ...search, stops[0].name ]
53
+ });
54
+
55
+ return;
56
+ }
57
+
9
58
  data.push({
10
59
  name: `${ city.name }, ${ city.country?.name ?? '' } (${ t('all_stations', { ns: 'common' }) })`,
11
- value: `${ city.slug }`
60
+ value: `${ city.slug }`,
61
+ search
12
62
  });
13
63
 
14
- city.stops?.forEach(stop => {
64
+ stops.forEach(stop => {
15
65
  data.push({
16
66
  name: `${ city.name }, ${ city.country?.name ?? '' } (${ stop.name })`,
17
- value: `${ city.slug }:${ stop.id }`
67
+ value: `${ city.slug }:${ stop.id }`,
68
+ // the stop's own name as well - station names are not translated
69
+ // (they are what is written on the building) but they are certainly
70
+ // searched for
71
+ search: [ ...search, stop.name ]
18
72
  });
19
73
  });
20
74
  });