@sarimarcus/content-sites-tourism 0.48.0 → 0.49.1
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 +27 -0
- package/package.json +4 -3
- package/src/internal/fill.ts +4 -0
- package/src/internal/labels.ts +19 -0
- package/src/sections/NeighborhoodBaseBlock.astro +69 -0
- package/src/sections/NeighborhoodCategory.astro +2 -1
- package/src/sections/NeighborhoodFigure.astro +20 -0
- package/src/sections/NeighborhoodHubRow.astro +59 -0
- package/src/sections/NeighborhoodLocatorMap.astro +42 -0
- package/src/sections/NeighborhoodShelf.astro +53 -0
- package/src/sections/ShelfCard.astro +92 -0
- package/src/sections/index.ts +8 -0
- package/src/templates/NeighborhoodDetailPage.astro +111 -0
- package/src/templates/NeighborhoodFacetPage.astro +11 -2
- package/src/templates/NeighborhoodHubPage.astro +68 -0
- package/src/templates/hubFilter.ts +46 -0
- package/src/templates/index.ts +4 -0
- package/src/templates/neighborhoodCore.ts +143 -0
- package/src/templates/neighborhoodModel.ts +370 -0
- package/src/templates/neighborhoods.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
All packages in the platform release in lockstep; entries are per release version.
|
|
4
4
|
|
|
5
|
+
## 0.49.1 (2026-10-26)
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `locator` slot on `NeighborhoodHubPage` and `NeighborhoodDetailPage` (SLA-3510): a site passes its own live map there in place of the not-to-scale SVG, which stays the fallback when the slot is absent or renders empty. Optional; nothing has to adopt it.
|
|
10
|
+
- `stops` on the hub model's `map` and the detail model's `locator`: one `LocatorStop` (`order`, `name`, `coordinates`, `type: 'neighborhood'`, `slug`) per neighbourhood with coordinates, numbered as in the hub list; the detail page's own neighbourhood carries `active: true`. `LocatorStop` is exported from `/neighborhoods`.
|
|
11
|
+
- `liveNote` (hub) and `liveCaption` (detail): the map copy without "Not to scale", shown when a live map is slotted.
|
|
12
|
+
|
|
13
|
+
## 0.49.0 (2026-10-25)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `@sarimarcus/content-sites-tourism/neighborhoods` (SLA-3444, neighbourhood redesign): the `areaType`, `badge`, `baseVerdict` and `picks` content fields (`neighborhoodSchemaFields(z)`), `FACET_MIN_ITEMS`, `shelfPlan`, `resolvePicks`, `rankItems`, `hubOrder`, `hubFilters`, the locator layout (`locatorPoints`, `centroid`, `distanceKm`), the facet helpers (`neighborhoodFacetItems`, `neighborhoodFacetCounts`) and the page models (`neighborhoodData`, `neighborhoodDetailModel`, `neighborhoodHubModel`).
|
|
18
|
+
- Templates `NeighborhoodDetailPage` (decide-first detail page) and `NeighborhoodHubPage` (where-to-stay hub with best-for filter and locator map); sections `ShelfCard`, `NeighborhoodShelf`, `NeighborhoodBaseBlock`, `NeighborhoodLocatorMap`, `NeighborhoodHubRow`, `NeighborhoodFigure`.
|
|
19
|
+
- `NeighborhoodFacetPage` takes optional `facetNav` and `gridHeading`.
|
|
20
|
+
|
|
21
|
+
### Breaking
|
|
22
|
+
|
|
23
|
+
The neighbourhood pages move onto the new templates; run on each tourism site, in this order, after `pin-bump.mjs` and `rewrite-imports.mjs --delete-local`:
|
|
24
|
+
|
|
25
|
+
- `migrations/neighborhood-fields.mjs`
|
|
26
|
+
- `migrations/neighborhood-detail.mjs`
|
|
27
|
+
- `migrations/neighborhood-hub.mjs`
|
|
28
|
+
- `migrations/neighborhood-facets.mjs`
|
|
29
|
+
|
|
30
|
+
They change the neighbourhood hub, detail and facet pages only (intended output change) and delete the three hub-only site components (`adapters.json` entries `remove`, done in 0.49.0).
|
|
31
|
+
|
|
5
32
|
## 0.48.0 (2026-10-24)
|
|
6
33
|
|
|
7
34
|
- No changes; lockstep release with ui (SLA-3435).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sarimarcus/content-sites-tourism",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.1",
|
|
4
4
|
"description": "City-tourism vertical: city-entity components, pages templates and utilities for the tourism sites.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
"./sections": "./src/sections/index.ts",
|
|
31
31
|
"./templates": "./src/templates/index.ts",
|
|
32
32
|
"./schema": "./src/schema/index.ts",
|
|
33
|
+
"./neighborhoods": "./src/templates/neighborhoods.ts",
|
|
33
34
|
"./llms": "./src/llms/index.ts",
|
|
34
35
|
"./tailwind.css": "./src/tailwind.css"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"astro": "^7.0.6",
|
|
38
39
|
"tailwindcss": "^4.1.18",
|
|
39
|
-
"@sarimarcus/content-sites-core": "0.
|
|
40
|
-
"@sarimarcus/content-sites-ui": "0.
|
|
40
|
+
"@sarimarcus/content-sites-core": "0.49.1",
|
|
41
|
+
"@sarimarcus/content-sites-ui": "0.49.1"
|
|
41
42
|
}
|
|
42
43
|
}
|
package/src/internal/labels.ts
CHANGED
|
@@ -30,4 +30,23 @@ export const LABELS = {
|
|
|
30
30
|
fallbackTypeLabel: 'Event',
|
|
31
31
|
},
|
|
32
32
|
monumentBodySlot: { didYouKnow: 'Did you know?', timeline: 'Timeline' },
|
|
33
|
+
neighborhoodModel: {
|
|
34
|
+
see: 'See', stay: 'Stay', eat: 'Eat', drink: 'Drink', do: 'Do', walk: 'Walk', eventsIn: 'Events in {name}',
|
|
35
|
+
baseHeading: 'Is {name} your base?', openMap: 'Open the map', noHotels: 'No hotels on our list yet',
|
|
36
|
+
allIn: 'All {count} {noun} in {name}', kmFrom: '{km} km from the {anchor}', beside: 'Beside the {anchor}',
|
|
37
|
+
insiderTips: 'Insider tips', otherHoods: 'Other neighbourhoods', allHoods: 'All neighbourhoods', googleMaps: 'Open in Google Maps',
|
|
38
|
+
detailMapAria: "Locator map of {city}'s neighbourhoods, not to scale, with {name} highlighted and the {anchor} marked.",
|
|
39
|
+
detailMapCaption: 'Where {name} sits. Not to scale.', detailLiveMapCaption: 'Where {name} sits.',
|
|
40
|
+
hubHeading: 'Where to stay in {city}, neighbourhood by neighbourhood',
|
|
41
|
+
hubStandfirst: '{count} areas compared as a base: who each suits, what is on the doorstep, and how far it is from the {anchor}.',
|
|
42
|
+
allAreas: 'All areas', filterAria: 'Filter neighbourhoods by who they suit', status: 'Showing {shown} of {total} neighbourhoods',
|
|
43
|
+
hubMapAria: "Locator map of {city}'s {count} neighbourhoods, numbered as in the list, with the {anchor} marked. Not to scale.",
|
|
44
|
+
hubMapSummary: 'Map of the {count} areas', hubMapNote: 'Numbers match the list. Not to scale: the list gives true straight-line distances from the {anchor}.', hubLiveMapNote: 'Numbers match the list.',
|
|
45
|
+
explore: 'Explore {name}', seeHotels: 'See the {count} hotels', siblingsLabel: 'Other neighbourhoods:',
|
|
46
|
+
hotel: ['hotel', 'hotels'] as const, restaurant: ['restaurant', 'restaurants'] as const, monument: ['monument', 'monuments'] as const,
|
|
47
|
+
museum: ['museum', 'museums'] as const, bar: ['bar', 'bars'] as const, activity: ['activity', 'activities'] as const, sight: ['sight', 'sights'] as const,
|
|
48
|
+
},
|
|
49
|
+
neighborhoodAreaTypes: { historic: 'Historic centre', authentic: 'Lived-in quarter', modern: 'Modern district' } as Record<string, string>,
|
|
50
|
+
neighborhoodBadges: { 'editors-pick': 'Editor’s pick', 'hidden-gem': 'Hidden gem', 'family-friendly': 'Family-friendly', 'tourist-centre': 'Tourist centre', nightlife: 'Nightlife' } as Record<string, string>,
|
|
51
|
+
neighborhoodFacets: { monuments: 'Monuments', hotels: 'Hotels', restaurants: 'Restaurants', bars: 'Bars', activities: 'Activities' } as Record<string, string>,
|
|
33
52
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodBaseBlock — "Is this your base?" at the top of a neighbourhood detail page: the base verdict, best-for
|
|
4
|
+
* tags, computed facts (distance to the anchor landmark, counts) with an optional map link, then up to three pick
|
|
5
|
+
* columns (Stay / Eat / See). The route resolves picks with `resolvePicks`; a column with no items is not rendered,
|
|
6
|
+
* and with fewer than two columns the block keeps only the verdict, tags and facts.
|
|
7
|
+
*/
|
|
8
|
+
import { Badge, Icon, LinkArrow } from '@sarimarcus/content-sites-ui/primitives';
|
|
9
|
+
import type { TrustedHtml } from '@sarimarcus/content-sites-ui/types';
|
|
10
|
+
|
|
11
|
+
export interface BaseFact { icon: string; label: string }
|
|
12
|
+
export interface BasePick { href: string; name: string; note?: string }
|
|
13
|
+
export interface BaseColumn { heading: string; icon: string; items: readonly BasePick[]; allLink?: { href: string; label: string } }
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
heading: string;
|
|
17
|
+
verdictHtml?: TrustedHtml;
|
|
18
|
+
tags?: readonly string[];
|
|
19
|
+
facts?: readonly BaseFact[];
|
|
20
|
+
mapLink?: { href: string; label: string };
|
|
21
|
+
columns?: readonly BaseColumn[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { heading, verdictHtml, tags = [], facts = [], mapLink, columns = [] } = Astro.props;
|
|
25
|
+
const shown = columns.filter((c) => c.items.length > 0);
|
|
26
|
+
const showColumns = shown.length >= 2;
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<section aria-labelledby="base-heading" class="my-8 lg:my-10 rounded-xl border border-border bg-card p-5 lg:p-7">
|
|
30
|
+
<h2 id="base-heading" class="font-display text-3xl leading-tight text-foreground">{heading}</h2>
|
|
31
|
+
{verdictHtml && <p class="mt-2 max-w-measure-wide text-lg text-foreground" set:html={verdictHtml} />}
|
|
32
|
+
{tags.length > 0 && (
|
|
33
|
+
<ul class="mt-3 flex flex-wrap gap-1.5" role="list">
|
|
34
|
+
{tags.map((t) => <li><Badge tone="neutral" size="sm">{t}</Badge></li>)}
|
|
35
|
+
</ul>
|
|
36
|
+
)}
|
|
37
|
+
{(facts.length > 0 || mapLink) && (
|
|
38
|
+
<ul class="mt-4 flex flex-wrap items-center gap-x-5 gap-y-1 text-sm text-muted-foreground tabular-nums" role="list">
|
|
39
|
+
{facts.map((f) => (
|
|
40
|
+
<li class="inline-flex items-center gap-1.5"><Icon name={f.icon} class="w-4 h-4" />{f.label}</li>
|
|
41
|
+
))}
|
|
42
|
+
{mapLink && (
|
|
43
|
+
<li><a href={mapLink.href} class="inline-flex items-center gap-1.5 min-h-[44px] text-secondary hover:text-primary"><Icon name="map-pin" class="w-4 h-4" />{mapLink.label}</a></li>
|
|
44
|
+
)}
|
|
45
|
+
</ul>
|
|
46
|
+
)}
|
|
47
|
+
{showColumns && (
|
|
48
|
+
<div class:list={['mt-6 grid gap-6', shown.length === 3 ? 'md:grid-cols-3' : 'md:grid-cols-2']}>
|
|
49
|
+
{shown.map((col) => (
|
|
50
|
+
<div>
|
|
51
|
+
<h3 class="flex items-center gap-2 border-b border-border pb-2 text-lg font-semibold text-foreground">
|
|
52
|
+
<Icon name={col.icon} class="w-4 h-4 text-primary" />{col.heading}
|
|
53
|
+
</h3>
|
|
54
|
+
<ol role="list">
|
|
55
|
+
{col.items.map((p) => (
|
|
56
|
+
<li>
|
|
57
|
+
<a href={p.href} class="flex min-h-[44px] items-center justify-between gap-3 border-b border-border/60 py-2 text-foreground hover:text-primary">
|
|
58
|
+
<span>{p.name}</span>
|
|
59
|
+
{p.note && <span class="whitespace-nowrap text-sm text-muted-foreground tabular-nums">{p.note}</span>}
|
|
60
|
+
</a>
|
|
61
|
+
</li>
|
|
62
|
+
))}
|
|
63
|
+
</ol>
|
|
64
|
+
{col.allLink && <LinkArrow href={col.allLink.href} size="sm" class="mt-2 min-h-[44px] inline-flex items-center">{col.allLink.label}</LinkArrow>}
|
|
65
|
+
</div>
|
|
66
|
+
))}
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
</section>
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* header. Cards go in the default slot. The site adapter supplies the title, description and count label.
|
|
5
5
|
*/
|
|
6
6
|
import { Icon } from '@sarimarcus/content-sites-ui/primitives';
|
|
7
|
+
import type { NeighborhoodCategory } from '../templates/neighborhoodCore';
|
|
7
8
|
|
|
8
|
-
export type NeighborhoodCategoryType =
|
|
9
|
+
export type NeighborhoodCategoryType = NeighborhoodCategory;
|
|
9
10
|
|
|
10
11
|
interface Props {
|
|
11
12
|
id: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodFigure — an image with a caption beside a neighbourhood detail-page block (the body, the insider tips):
|
|
4
|
+
* the item's responsive image, or `fallbackSrc` when it has none.
|
|
5
|
+
*/
|
|
6
|
+
import { ResponsiveImage } from '@sarimarcus/content-sites-ui/primitives';
|
|
7
|
+
import type { ImageMetadata } from 'astro';
|
|
8
|
+
|
|
9
|
+
export interface DetailFigure { image?: ImageMetadata; fallbackSrc: string; alt: string; caption: string }
|
|
10
|
+
|
|
11
|
+
interface Props { figure: DetailFigure }
|
|
12
|
+
|
|
13
|
+
const { figure } = Astro.props;
|
|
14
|
+
const cls = 'w-full aspect-[16/10] lg:aspect-[4/5] object-cover rounded-lg';
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<figure class="m-0">
|
|
18
|
+
{figure.image ? <ResponsiveImage src={figure.image} alt={figure.alt} sizes="(min-width: 1024px) 320px, 100vw" class={cls} loading="lazy" /> : <img src={figure.fallbackSrc} alt={figure.alt} class={cls} loading="lazy" />}
|
|
19
|
+
<figcaption class="mt-2 text-sm text-muted-foreground">{figure.caption}</figcaption>
|
|
20
|
+
</figure>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodHubRow — one neighbourhood on the hub's "choose your base" list: its number (matching the locator map),
|
|
4
|
+
* name and area type, the base verdict, best-for tags, computed facts and the links. `filterValues` feeds the hub
|
|
5
|
+
* filter (`data-tags`); `hotelsLink` is passed only when the hotels facet exists.
|
|
6
|
+
*/
|
|
7
|
+
import { Badge, Icon, LinkArrow, ResponsiveImage } from '@sarimarcus/content-sites-ui/primitives';
|
|
8
|
+
import type { ImageMetadata } from 'astro';
|
|
9
|
+
import type { BaseFact } from './NeighborhoodBaseBlock.astro';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
slug: string;
|
|
13
|
+
number: number;
|
|
14
|
+
name: string;
|
|
15
|
+
href: string;
|
|
16
|
+
areaLabel?: string;
|
|
17
|
+
verdict?: string;
|
|
18
|
+
tags?: readonly string[];
|
|
19
|
+
filterValues?: readonly string[];
|
|
20
|
+
facts?: readonly BaseFact[];
|
|
21
|
+
exploreLabel: string;
|
|
22
|
+
hotelsLink?: { href: string; label: string };
|
|
23
|
+
image?: ImageMetadata;
|
|
24
|
+
fallbackSrc: string;
|
|
25
|
+
imageAlt: string;
|
|
26
|
+
/** The first rows load eagerly. */
|
|
27
|
+
eager?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { slug, number, name, href, areaLabel, verdict, tags = [], filterValues = [], facts = [], exploreLabel, hotelsLink, image, fallbackSrc, imageAlt, eager = false } = Astro.props;
|
|
31
|
+
const imgClass = 'w-full aspect-[4/3] object-cover rounded-lg';
|
|
32
|
+
const loading = eager ? 'eager' : 'lazy';
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
<li data-hub-row={slug} data-tags={filterValues.join('|')} class="grid grid-cols-[5.5rem_minmax(0,1fr)] sm:grid-cols-[8.5rem_minmax(0,1fr)] gap-4 sm:gap-5 py-4 border-b border-border">
|
|
36
|
+
<a href={href} tabindex="-1" aria-hidden="true" class="block">
|
|
37
|
+
{image ? <ResponsiveImage src={image} alt={imageAlt} sizes="(min-width: 640px) 136px, 88px" class={imgClass} loading={loading} /> : <img src={fallbackSrc} alt={imageAlt} class={imgClass} loading={loading} />}
|
|
38
|
+
</a>
|
|
39
|
+
<div class="min-w-0">
|
|
40
|
+
<h2 class="flex flex-wrap items-baseline gap-x-2.5 font-display text-xl sm:text-2xl leading-tight text-foreground">
|
|
41
|
+
<span class="text-base text-primary tabular-nums" aria-hidden="true">{number}</span>
|
|
42
|
+
<a href={href} class="hover:text-primary">{name}</a>
|
|
43
|
+
{areaLabel && areaLabel.toLowerCase() !== name.toLowerCase() && <span class="font-body text-sm text-muted-foreground">{areaLabel}</span>}
|
|
44
|
+
</h2>
|
|
45
|
+
{verdict && <p class="mt-1 max-w-measure text-foreground">{verdict}</p>}
|
|
46
|
+
{tags.length > 0 && (
|
|
47
|
+
<ul class="mt-2 flex flex-wrap gap-1.5" role="list">{tags.map((t) => <li><Badge tone="neutral" size="sm">{t}</Badge></li>)}</ul>
|
|
48
|
+
)}
|
|
49
|
+
{facts.length > 0 && (
|
|
50
|
+
<ul class="mt-2 flex flex-wrap gap-x-4 gap-y-0.5 text-sm text-muted-foreground tabular-nums" role="list">
|
|
51
|
+
{facts.map((f) => <li class="inline-flex items-center gap-1.5"><Icon name={f.icon} class="w-4 h-4" />{f.label}</li>)}
|
|
52
|
+
</ul>
|
|
53
|
+
)}
|
|
54
|
+
<p class="mt-1 flex flex-wrap gap-x-5">
|
|
55
|
+
<LinkArrow href={href} class="inline-flex min-h-[44px] items-center font-semibold">{exploreLabel}</LinkArrow>
|
|
56
|
+
{hotelsLink && <a href={hotelsLink.href} class="inline-flex min-h-[44px] items-center text-secondary hover:text-primary">{hotelsLink.label}</a>}
|
|
57
|
+
</p>
|
|
58
|
+
</div>
|
|
59
|
+
</li>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodLocatorMap — the not-to-scale locator SVG of the neighbourhoods hub and detail page: one numbered point
|
|
4
|
+
* per neighbourhood (numbers match the hub list), the anchor landmark as a diamond, `active` filled. Positions come
|
|
5
|
+
* from `locatorPoints`; no tiles, no script. The numbered list on the page is its text equivalent, so the SVG carries
|
|
6
|
+
* one `aria-label` and each point a `<title>`.
|
|
7
|
+
*/
|
|
8
|
+
import type { LocatorLayout } from '../templates/neighborhoodCore';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
layout: LocatorLayout;
|
|
12
|
+
/** slug → the number shown in the point and in the list. */
|
|
13
|
+
numbers: Readonly<Record<string, number>>;
|
|
14
|
+
/** slug → name, for each point's tooltip. */
|
|
15
|
+
names: Readonly<Record<string, string>>;
|
|
16
|
+
anchorLabel: string;
|
|
17
|
+
ariaLabel: string;
|
|
18
|
+
active?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { layout, numbers, names, anchorLabel, ariaLabel, active, class: className = '' } = Astro.props;
|
|
23
|
+
const { width, height, anchor, points } = layout;
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
<svg viewBox={`0 0 ${width} ${height}`} role="img" aria-label={ariaLabel} class:list={['block w-full h-auto', className]} data-locator-map>
|
|
27
|
+
<rect x="1" y="1" width={width - 2} height={height - 2} rx="8" class="fill-muted" />
|
|
28
|
+
<g transform={`translate(${anchor.x} ${anchor.y})`}>
|
|
29
|
+
<rect x="-6" y="-6" width="12" height="12" transform="rotate(45)" class="fill-accent stroke-accent-strong" />
|
|
30
|
+
</g>
|
|
31
|
+
<text x={anchor.x + 11} y={anchor.y + 4} font-size="11" class="fill-muted-foreground">{anchorLabel}</text>
|
|
32
|
+
{points.map((p) => {
|
|
33
|
+
const on = p.slug === active;
|
|
34
|
+
return (
|
|
35
|
+
<g data-locator-point={p.slug}>
|
|
36
|
+
<title>{names[p.slug] ?? p.slug}</title>
|
|
37
|
+
<circle cx={p.x} cy={p.y} r={on ? 12 : 10} stroke-width="1.5" class:list={['stroke-primary', on ? 'fill-primary' : 'fill-card']} />
|
|
38
|
+
<text x={p.x} y={p.y + 4} text-anchor="middle" font-size="11" class:list={[on ? 'fill-primary-foreground' : 'fill-primary-strong']}>{numbers[p.slug] ?? ''}</text>
|
|
39
|
+
</g>
|
|
40
|
+
);
|
|
41
|
+
})}
|
|
42
|
+
</svg>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodShelf — one shelf of the neighbourhood detail page (See, Stay, Eat, Drink, Do, Walk, Events): heading,
|
|
4
|
+
* the "All N … in X" facet link when the facet exists, the neighbourhood's own intro, and the items as ShelfCards in
|
|
5
|
+
* the shelf's layout. A `strip` shelf renders through ui CardCarousel (arrows, dots, view-all link). The route caps
|
|
6
|
+
* the items (`shelfPlan`) and passes them already resolved. An empty shelf renders nothing.
|
|
7
|
+
*/
|
|
8
|
+
import { LinkArrow } from '@sarimarcus/content-sites-ui/primitives';
|
|
9
|
+
import { CardCarousel } from '@sarimarcus/content-sites-ui/composed';
|
|
10
|
+
import type { TrustedHtml } from '@sarimarcus/content-sites-ui/types';
|
|
11
|
+
import ShelfCard from './ShelfCard.astro';
|
|
12
|
+
import type { ShelfCardItem, ShelfCardLayout } from './ShelfCard.astro';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
id: string;
|
|
16
|
+
heading: string;
|
|
17
|
+
items: readonly ShelfCardItem[];
|
|
18
|
+
layout: ShelfCardLayout;
|
|
19
|
+
/** textAsHtml() for plain text, trustedHtml() for rendered markdown. */
|
|
20
|
+
introHtml?: TrustedHtml;
|
|
21
|
+
facetLink?: { href: string; label: string };
|
|
22
|
+
/** Pagefind skips the shelf (lists that repeat other pages' content). */
|
|
23
|
+
pagefindIgnore?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { id, heading, items, layout, introHtml, facetLink, pagefindIgnore = false } = Astro.props;
|
|
27
|
+
const list = {
|
|
28
|
+
feature: 'grid gap-x-8 gap-y-6 md:grid-cols-2',
|
|
29
|
+
tile: 'grid gap-4 grid-cols-2 lg:grid-cols-4',
|
|
30
|
+
row: 'grid gap-x-8 gap-y-5 md:grid-cols-2',
|
|
31
|
+
thumb: 'grid gap-3 sm:grid-cols-2 lg:grid-cols-3',
|
|
32
|
+
}[layout];
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
{items.length > 0 && layout === 'strip' && (
|
|
36
|
+
<section id={id} class="py-10 lg:py-12 border-t border-border scroll-mt-20" data-pagefind-ignore={pagefindIgnore ? '' : undefined}>
|
|
37
|
+
<CardCarousel heading={heading} viewAllHref={facetLink?.href} viewAllLabel={facetLink?.label}>
|
|
38
|
+
{items.map((item) => <div class="snap-start shrink-0 w-[70vw] sm:w-60"><ShelfCard item={item} layout="strip" /></div>)}
|
|
39
|
+
</CardCarousel>
|
|
40
|
+
</section>
|
|
41
|
+
)}
|
|
42
|
+
{items.length > 0 && layout !== 'strip' && (
|
|
43
|
+
<section id={id} class="py-10 lg:py-12 border-t border-border scroll-mt-20" data-pagefind-ignore={pagefindIgnore ? '' : undefined}>
|
|
44
|
+
<div class="flex flex-wrap items-baseline justify-between gap-x-6 gap-y-1 mb-2">
|
|
45
|
+
<h2 class="font-display text-3xl text-foreground">{heading}</h2>
|
|
46
|
+
{facetLink && <LinkArrow href={facetLink.href} class="min-h-[44px] inline-flex items-center">{facetLink.label}</LinkArrow>}
|
|
47
|
+
</div>
|
|
48
|
+
{introHtml && <p class="max-w-measure text-muted-foreground mb-6" set:html={introHtml} />}
|
|
49
|
+
<ul class={list} role="list">
|
|
50
|
+
{items.map((item) => <li><ShelfCard item={item} layout={layout} /></li>)}
|
|
51
|
+
</ul>
|
|
52
|
+
</section>
|
|
53
|
+
)}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* ShelfCard — one item on a neighbourhood detail-page shelf, linked as a whole. Each `layout` is a different card so
|
|
4
|
+
* that no two shelves on a page share a grid: `feature` (16:9 image, name, one sentence), `tile` (3:2 image in a
|
|
5
|
+
* bordered card), `row` (image left, meta and sentence right), `thumb` (square thumbnail and name), `strip` (4:3
|
|
6
|
+
* image and name, for horizontal strips). The route resolves the image; without one the card shows `fallbackSrc`.
|
|
7
|
+
*/
|
|
8
|
+
import { ResponsiveImage } from '@sarimarcus/content-sites-ui/primitives';
|
|
9
|
+
import type { ImageMetadata } from 'astro';
|
|
10
|
+
|
|
11
|
+
export type ShelfCardLayout = 'feature' | 'tile' | 'row' | 'thumb' | 'strip';
|
|
12
|
+
|
|
13
|
+
export interface ShelfCardItem {
|
|
14
|
+
href: string;
|
|
15
|
+
name: string;
|
|
16
|
+
image?: ImageMetadata;
|
|
17
|
+
fallbackSrc: string;
|
|
18
|
+
imageAlt: string;
|
|
19
|
+
/** Short facts joined with a middle dot: category, price, rating, distance, duration. */
|
|
20
|
+
meta?: string[];
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
item: ShelfCardItem;
|
|
26
|
+
layout: ShelfCardLayout;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { item, layout } = Astro.props;
|
|
30
|
+
const ratio = { feature: 'aspect-video', tile: 'aspect-[3/2]', row: 'aspect-[4/3]', thumb: 'aspect-square', strip: 'aspect-[4/3]' }[layout];
|
|
31
|
+
const sizes = {
|
|
32
|
+
feature: '(min-width: 768px) 560px, 100vw',
|
|
33
|
+
tile: '(min-width: 1024px) 270px, 50vw',
|
|
34
|
+
row: '(min-width: 768px) 160px, 112px',
|
|
35
|
+
thumb: '72px',
|
|
36
|
+
strip: '(min-width: 768px) 240px, 70vw',
|
|
37
|
+
}[layout];
|
|
38
|
+
const imgClass = `w-full h-full object-cover ${ratio}`;
|
|
39
|
+
const meta = (item.meta ?? []).filter(Boolean).join(' · ');
|
|
40
|
+
const wrap = {
|
|
41
|
+
feature: 'group block',
|
|
42
|
+
tile: 'group block h-full overflow-hidden rounded-xl border border-border bg-card',
|
|
43
|
+
row: 'group grid grid-cols-[7rem_minmax(0,1fr)] md:grid-cols-[10rem_minmax(0,1fr)] gap-4 items-start',
|
|
44
|
+
thumb: 'group flex items-center gap-3 min-h-[44px]',
|
|
45
|
+
strip: 'group block',
|
|
46
|
+
}[layout];
|
|
47
|
+
const frame = {
|
|
48
|
+
feature: 'overflow-hidden rounded-lg',
|
|
49
|
+
tile: 'overflow-hidden',
|
|
50
|
+
row: 'overflow-hidden rounded-lg',
|
|
51
|
+
thumb: 'w-[4.5rem] flex-none overflow-hidden rounded-lg',
|
|
52
|
+
strip: 'overflow-hidden rounded-lg',
|
|
53
|
+
}[layout];
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
<a href={item.href} class={wrap} data-shelf-card={layout}>
|
|
57
|
+
<div class={frame}>
|
|
58
|
+
{item.image ? (
|
|
59
|
+
<ResponsiveImage src={item.image} alt={item.imageAlt} sizes={sizes} class={imgClass} loading="lazy" decoding="async" />
|
|
60
|
+
) : (
|
|
61
|
+
<img src={item.fallbackSrc} alt={item.imageAlt} class={imgClass} loading="lazy" decoding="async" />
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
{layout === 'feature' && (
|
|
65
|
+
<div class="mt-3">
|
|
66
|
+
<h3 class="font-display text-xl text-foreground group-hover:text-primary transition-colors">{item.name}</h3>
|
|
67
|
+
{item.description && <p class="mt-1 text-sm text-muted-foreground">{item.description}</p>}
|
|
68
|
+
</div>
|
|
69
|
+
)}
|
|
70
|
+
{layout === 'tile' && (
|
|
71
|
+
<div class="p-4">
|
|
72
|
+
<h3 class="text-lg font-semibold leading-snug text-foreground group-hover:text-primary transition-colors">{item.name}</h3>
|
|
73
|
+
{meta && <p class="mt-1 text-sm text-muted-foreground tabular-nums">{meta}</p>}
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
{layout === 'row' && (
|
|
77
|
+
<div>
|
|
78
|
+
<h3 class="font-display text-xl leading-tight text-foreground group-hover:text-primary transition-colors">{item.name}</h3>
|
|
79
|
+
{meta && <p class="mt-1 text-sm text-muted-foreground tabular-nums">{meta}</p>}
|
|
80
|
+
{item.description && <p class="mt-1.5 text-sm text-foreground/80">{item.description}</p>}
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
{layout === 'thumb' && (
|
|
84
|
+
<h3 class="text-base font-semibold text-foreground group-hover:text-primary transition-colors">{item.name}</h3>
|
|
85
|
+
)}
|
|
86
|
+
{layout === 'strip' && (
|
|
87
|
+
<div class="mt-2">
|
|
88
|
+
<h3 class="text-base font-semibold leading-snug text-foreground group-hover:text-primary transition-colors">{item.name}</h3>
|
|
89
|
+
{meta && <p class="mt-0.5 text-sm text-muted-foreground tabular-nums">{meta}</p>}
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
</a>
|
package/src/sections/index.ts
CHANGED
|
@@ -15,7 +15,15 @@ export { default as ArticleCardGrid } from './ArticleCardGrid.astro';
|
|
|
15
15
|
export { default as RelatedBlock } from './RelatedBlock.astro';
|
|
16
16
|
export { default as MonumentHero } from './MonumentHero.astro';
|
|
17
17
|
export { default as QuartierHero } from './QuartierHero.astro';
|
|
18
|
+
export { default as ShelfCard } from './ShelfCard.astro';
|
|
19
|
+
export { default as NeighborhoodShelf } from './NeighborhoodShelf.astro';
|
|
20
|
+
export { default as NeighborhoodBaseBlock } from './NeighborhoodBaseBlock.astro';
|
|
21
|
+
export { default as NeighborhoodLocatorMap } from './NeighborhoodLocatorMap.astro';
|
|
22
|
+
export { default as NeighborhoodHubRow } from './NeighborhoodHubRow.astro';
|
|
23
|
+
export { default as NeighborhoodFigure } from './NeighborhoodFigure.astro';
|
|
18
24
|
export type { WalkStop } from './WalkStops.astro';
|
|
25
|
+
export type { ShelfCardItem, ShelfCardLayout } from './ShelfCard.astro';
|
|
26
|
+
export type { BaseColumn, BaseFact, BasePick } from './NeighborhoodBaseBlock.astro';
|
|
19
27
|
export type { WhoItsForTag } from './WhoItsFor.astro';
|
|
20
28
|
export type { NeighborhoodCategoryType } from './NeighborhoodCategory.astro';
|
|
21
29
|
export type { SituationalScenario } from './SituationalNav.astro';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodDetailPage — /neighborhood/<slug> (SLA-3448, design SLA-3446): decide first, then capped shelves. Order:
|
|
4
|
+
* hero, byline, "Is this your base?", the editorial body beside a figure, the shelves in the route's order
|
|
5
|
+
* (See, Stay, Eat, Drink, Do, Walk, Events), `after-shelves` (affiliate tours, walking route), insider tips beside a
|
|
6
|
+
* figure, people, FAQ beside the locator map, sources, then the closer with the other neighbourhoods as a pill row after
|
|
7
|
+
* it (the related zone is one role: the closer; siblings stay a nav, never a second card grid).
|
|
8
|
+
*
|
|
9
|
+
* The route keeps Layout, StructuredData, the data and every string. It resolves images, caps each shelf with
|
|
10
|
+
* `shelfPlan` and the picks with `resolvePicks`, and passes the site's own components in slots: `breadcrumb`, `hero`,
|
|
11
|
+
* `byline`, `people`, `body` (DetailBody), `after-shelves`, `faq`, `locator` (the site's live map, in place of the SVG),
|
|
12
|
+
* `sources`, `closer`.
|
|
13
|
+
*/
|
|
14
|
+
import { EntityDetailShell, Container } from '@sarimarcus/content-sites-ui/layout';
|
|
15
|
+
import { Chip, Icon } from '@sarimarcus/content-sites-ui/primitives';
|
|
16
|
+
import type { TrustedHtml } from '@sarimarcus/content-sites-ui/types';
|
|
17
|
+
import NeighborhoodBaseBlock from '../sections/NeighborhoodBaseBlock.astro';
|
|
18
|
+
import type { BaseColumn, BaseFact } from '../sections/NeighborhoodBaseBlock.astro';
|
|
19
|
+
import NeighborhoodShelf from '../sections/NeighborhoodShelf.astro';
|
|
20
|
+
import NeighborhoodLocatorMap from '../sections/NeighborhoodLocatorMap.astro';
|
|
21
|
+
import NeighborhoodFigure from '../sections/NeighborhoodFigure.astro';
|
|
22
|
+
import type { DetailFigure } from '../sections/NeighborhoodFigure.astro';
|
|
23
|
+
import type { ShelfCardItem, ShelfCardLayout } from '../sections/ShelfCard.astro';
|
|
24
|
+
import type { LocatorLayout } from './neighborhoodCore';
|
|
25
|
+
|
|
26
|
+
export interface DetailShelf {
|
|
27
|
+
id: string;
|
|
28
|
+
heading: string;
|
|
29
|
+
layout: ShelfCardLayout;
|
|
30
|
+
items: readonly ShelfCardItem[];
|
|
31
|
+
introHtml?: TrustedHtml;
|
|
32
|
+
facetLink?: { href: string; label: string };
|
|
33
|
+
pagefindIgnore?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export type { DetailFigure };
|
|
36
|
+
export interface DetailTip { title?: string; body: string }
|
|
37
|
+
export interface DetailSiblings { label: string; ariaLabel: string; items: readonly { href: string; name: string }[]; all: { href: string; label: string } }
|
|
38
|
+
|
|
39
|
+
interface Props {
|
|
40
|
+
slug: string;
|
|
41
|
+
audiences?: readonly string[];
|
|
42
|
+
base: {
|
|
43
|
+
heading: string;
|
|
44
|
+
verdictHtml?: TrustedHtml;
|
|
45
|
+
tags?: readonly string[];
|
|
46
|
+
facts?: readonly BaseFact[];
|
|
47
|
+
mapLink?: { href: string; label: string };
|
|
48
|
+
columns?: readonly BaseColumn[];
|
|
49
|
+
};
|
|
50
|
+
bodyFigure?: DetailFigure;
|
|
51
|
+
shelves: readonly DetailShelf[];
|
|
52
|
+
tips?: { heading: string; items: readonly DetailTip[]; figure?: DetailFigure };
|
|
53
|
+
locator?: { layout: LocatorLayout; numbers: Record<string, number>; names: Record<string, string>; anchorLabel: string; ariaLabel: string; caption: string; liveCaption?: string; mapLink?: { href: string; label: string } };
|
|
54
|
+
siblings?: DetailSiblings;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { slug, audiences = [], base, bodyFigure, shelves, tips, locator, siblings } = Astro.props;
|
|
58
|
+
// Rendered, not slots.has alone: a site's `{cond && <Map slot="locator" />}` counts as present even when cond is false.
|
|
59
|
+
const locatorHtml = Astro.slots.has('locator') ? (await Astro.slots.render('locator')).trim() : '';
|
|
60
|
+
const live = locatorHtml !== '';
|
|
61
|
+
const hasTips = Boolean(tips && tips.items.length);
|
|
62
|
+
const hasFaq = Astro.slots.has('faq');
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
<EntityDetailShell pagefindType="neighborhood" pagefindScope="page" audiences={audiences} column={false}><slot name="breadcrumb" slot="breadcrumb" /><slot name="hero" slot="hero" /><Container>
|
|
66
|
+
<slot name="byline" />
|
|
67
|
+
<NeighborhoodBaseBlock {...base} />
|
|
68
|
+
<div class:list={['grid gap-8 lg:gap-12', bodyFigure && 'lg:grid-cols-[minmax(0,1fr)_20rem]']}>
|
|
69
|
+
<div class="min-w-0 max-w-measure"><slot name="body" /></div>
|
|
70
|
+
{bodyFigure && <NeighborhoodFigure figure={bodyFigure} />}
|
|
71
|
+
</div>
|
|
72
|
+
{shelves.map((s) => <NeighborhoodShelf {...s} />)}
|
|
73
|
+
<slot name="after-shelves" />
|
|
74
|
+
{hasTips && tips && (
|
|
75
|
+
<section id="insider-tips" class="py-10 lg:py-12 border-t border-border scroll-mt-20">
|
|
76
|
+
<h2 class="font-display text-3xl text-foreground mb-5">{tips.heading}</h2>
|
|
77
|
+
<div class:list={['grid gap-8 lg:gap-12', tips.figure && 'lg:grid-cols-[minmax(0,1fr)_20rem]']}>
|
|
78
|
+
<ul class="grid gap-3 max-w-measure" role="list">
|
|
79
|
+
{tips.items.map((t) => (
|
|
80
|
+
<li class="rounded-lg bg-muted p-4 lg:p-5">{t.title && <strong class="font-semibold text-foreground">{t.title} </strong>}<span class="text-foreground/85">{t.body}</span></li>
|
|
81
|
+
))}
|
|
82
|
+
</ul>
|
|
83
|
+
{tips.figure && <NeighborhoodFigure figure={tips.figure} />}
|
|
84
|
+
</div>
|
|
85
|
+
</section>
|
|
86
|
+
)}
|
|
87
|
+
<slot name="people" />
|
|
88
|
+
{(hasFaq || locator) && (
|
|
89
|
+
<section id="faq-map" class="py-10 lg:py-12 border-t border-border scroll-mt-20">
|
|
90
|
+
<div class:list={['grid gap-8 lg:gap-12', locator && hasFaq && 'lg:grid-cols-[minmax(0,1fr)_20rem]']}>
|
|
91
|
+
{hasFaq && <div class="min-w-0 max-w-measure"><slot name="faq" /></div>}
|
|
92
|
+
{locator && (
|
|
93
|
+
<figure id="map" class="m-0 scroll-mt-20">
|
|
94
|
+
{live ? <Fragment set:html={locatorHtml} /> : <NeighborhoodLocatorMap layout={locator.layout} numbers={locator.numbers} names={locator.names} anchorLabel={locator.anchorLabel} ariaLabel={locator.ariaLabel} active={slug} />}
|
|
95
|
+
<figcaption class="mt-2 text-sm text-muted-foreground">
|
|
96
|
+
{live ? (locator.liveCaption ?? locator.caption) : locator.caption}
|
|
97
|
+
{locator.mapLink && <a href={locator.mapLink.href} class="ml-1 inline-flex min-h-[44px] items-center text-secondary hover:text-primary">{locator.mapLink.label}</a>}
|
|
98
|
+
</figcaption>
|
|
99
|
+
</figure>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
</section>
|
|
103
|
+
)}
|
|
104
|
+
<slot name="sources" />
|
|
105
|
+
</Container><Fragment slot="closer"><slot name="closer" />{siblings && siblings.items.length > 0 && (
|
|
106
|
+
<nav aria-label={siblings.ariaLabel} data-pagefind-ignore class="mt-10 pt-6 border-t border-border/60 flex flex-wrap items-center gap-3">
|
|
107
|
+
<span class="text-sm text-muted-foreground">{siblings.label}</span>
|
|
108
|
+
{siblings.items.map((n) => <Chip href={n.href} size="sm" text="sm" tone="muted" accent="primary">{n.name}</Chip>)}
|
|
109
|
+
<Chip href={siblings.all.href} size="sm" text="sm" tone="tint" accent="primary">{siblings.all.label}<Icon name="arrow-right" class="w-3.5 h-3.5" aria-hidden="true" /></Chip>
|
|
110
|
+
</nav>
|
|
111
|
+
)}</Fragment></EntityDetailShell>
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
import { ArrowLabel, Icon } from '@sarimarcus/content-sites-ui/primitives';
|
|
10
10
|
import { Container } from '@sarimarcus/content-sites-ui/layout';
|
|
11
11
|
import FacetHero from './FacetHero.astro';
|
|
12
|
+
import FacetChipNav from './FacetChipNav.astro';
|
|
12
13
|
import type { TrustedHtml } from '@sarimarcus/content-sites-ui/types';
|
|
13
|
-
import type { FacetLink } from './facet';
|
|
14
|
+
import type { FacetLink, FacetNav } from './facet';
|
|
14
15
|
|
|
15
16
|
export type NeighborhoodFacetTone = 'overlay-secondary' | 'secondary' | 'primary-overlay' | 'accent-overlay';
|
|
16
17
|
|
|
@@ -31,9 +32,13 @@ interface Props {
|
|
|
31
32
|
/** Further bottom links (the type's listing, all neighbourhoods). */
|
|
32
33
|
moreLinks: FacetLink[];
|
|
33
34
|
columns?: 2 | 3;
|
|
35
|
+
/** The neighbourhood's other facets as chips (`neighborhoodFacetItems`), above the grid. */
|
|
36
|
+
facetNav?: FacetNav;
|
|
37
|
+
/** H2 above the grid, e.g. "All 12 restaurants in La Judería". */
|
|
38
|
+
gridHeading?: string;
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
const { tone, icon, badgeLabel, heading, lede, introHtml, backLink, guideLink, moreLinks, columns = 2 } = Astro.props;
|
|
41
|
+
const { tone, icon, badgeLabel, heading, lede, introHtml, backLink, guideLink, moreLinks, columns = 2, facetNav, gridHeading } = Astro.props;
|
|
37
42
|
|
|
38
43
|
const heroTones: Record<NeighborhoodFacetTone, string> = {
|
|
39
44
|
'overlay-secondary': 'bg-gradient-to-b from-overlay to-secondary-strong',
|
|
@@ -72,8 +77,12 @@ const gridClass = columns === 3 ? 'grid gap-6 sm:grid-cols-2 lg:grid-cols-3' : '
|
|
|
72
77
|
</div>
|
|
73
78
|
)}
|
|
74
79
|
|
|
80
|
+
{facetNav && facetNav.items.length > 1 && <FacetChipNav nav={facetNav} />}
|
|
81
|
+
|
|
75
82
|
<slot name="before-grid" />
|
|
76
83
|
|
|
84
|
+
{gridHeading && <h2 class="font-display text-2xl sm:text-3xl text-foreground mb-6">{gridHeading}</h2>}
|
|
85
|
+
|
|
77
86
|
<div class={gridClass}>
|
|
78
87
|
<slot />
|
|
79
88
|
</div>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* NeighborhoodHubPage — /neighborhoods (SLA-3449, design SLA-3446): "where to stay, neighbourhood by neighbourhood".
|
|
4
|
+
* A compact head (H1, one-line standfirst), the best-for filter (hidden until hubFilter.ts runs), the numbered rows
|
|
5
|
+
* and, beside them, the locator map (the not-to-scale SVG, or the site's live map passed as `locator`; sticky and open on desktop, collapsed below the list on mobile).
|
|
6
|
+
*
|
|
7
|
+
* The route keeps Layout, StructuredData, the data and every string, renders the rows as NeighborhoodHubRow children
|
|
8
|
+
* of the default slot, and passes `breadcrumb` and `after` (ItineraryTeaser, AlsoExplore). `statusTemplate` holds
|
|
9
|
+
* `{shown}` and `{total}`.
|
|
10
|
+
*/
|
|
11
|
+
import { ListingShell } from '@sarimarcus/content-sites-ui/layout';
|
|
12
|
+
import { Chip } from '@sarimarcus/content-sites-ui/primitives';
|
|
13
|
+
import NeighborhoodLocatorMap from '../sections/NeighborhoodLocatorMap.astro';
|
|
14
|
+
import type { LocatorLayout } from './neighborhoodCore';
|
|
15
|
+
import { countText } from './hubFilter.ts';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
heading: string;
|
|
19
|
+
standfirst: string;
|
|
20
|
+
filters: readonly { value: string; label: string }[];
|
|
21
|
+
allLabel: string;
|
|
22
|
+
filterAriaLabel: string;
|
|
23
|
+
statusTemplate: string;
|
|
24
|
+
total: number;
|
|
25
|
+
map?: { layout: LocatorLayout; numbers: Record<string, number>; names: Record<string, string>; anchorLabel: string; ariaLabel: string; summary: string; note: string; liveNote?: string };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { heading, standfirst, filters, allLabel, filterAriaLabel, statusTemplate, total, map } = Astro.props;
|
|
29
|
+
// Rendered, not slots.has alone: a site's `{cond && <Map slot="locator" />}` counts as present even when cond is false.
|
|
30
|
+
const locatorHtml = Astro.slots.has('locator') ? (await Astro.slots.render('locator')).trim() : '';
|
|
31
|
+
const live = locatorHtml !== '';
|
|
32
|
+
const status = countText(statusTemplate, total, total);
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
<ListingShell mainClass="pt-6 pb-12 lg:pt-8 lg:pb-16"><slot name="breadcrumb" slot="breadcrumb" /><div data-hub>
|
|
36
|
+
<header class="max-w-measure-wide">
|
|
37
|
+
<h1 class="font-display text-4xl sm:text-5xl leading-tight text-foreground">{heading}</h1>
|
|
38
|
+
<p class="mt-3 max-w-deck text-lg text-muted-foreground">{standfirst}</p>
|
|
39
|
+
</header>
|
|
40
|
+
{filters.length > 0 && (
|
|
41
|
+
<div data-hub-filters hidden role="group" aria-label={filterAriaLabel} class="mt-5 flex gap-2 overflow-x-auto pb-1">
|
|
42
|
+
<Chip as="button" type="button" size="md" active={true} hover={false} data-hub-filter="" aria-pressed="true">{allLabel}</Chip>
|
|
43
|
+
{filters.map((f) => <Chip as="button" type="button" size="md" active={false} hover={false} data-hub-filter={f.value} aria-pressed="false">{f.label}</Chip>)}
|
|
44
|
+
</div>
|
|
45
|
+
)}
|
|
46
|
+
<p data-hub-filter-status data-template={statusTemplate} aria-live="polite" class="sr-only">{status}</p>
|
|
47
|
+
<div class:list={['mt-4 grid gap-8 lg:gap-12', map && 'lg:grid-cols-[minmax(0,1fr)_20rem]']}>
|
|
48
|
+
<ol class="border-t border-border" role="list"><slot /></ol>
|
|
49
|
+
{map && (
|
|
50
|
+
<details data-hub-map class="order-last self-start rounded-xl border border-border bg-card p-4 lg:sticky lg:top-24">
|
|
51
|
+
<summary class="flex min-h-[44px] cursor-pointer items-center font-display text-lg text-foreground">{map.summary}</summary>
|
|
52
|
+
<p class="mb-2 text-xs text-muted-foreground">{live ? (map.liveNote ?? map.note) : map.note}</p>
|
|
53
|
+
{live ? <Fragment set:html={locatorHtml} /> : <NeighborhoodLocatorMap layout={map.layout} numbers={map.numbers} names={map.names} anchorLabel={map.anchorLabel} ariaLabel={map.ariaLabel} />}
|
|
54
|
+
</details>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
<slot name="after" />
|
|
58
|
+
</div></ListingShell>
|
|
59
|
+
|
|
60
|
+
<script>
|
|
61
|
+
import { initHubFilters } from './hubFilter.ts';
|
|
62
|
+
const openMap = () => {
|
|
63
|
+
if (window.matchMedia('(min-width: 1024px)').matches) document.querySelectorAll<HTMLDetailsElement>('details[data-hub-map]').forEach((d) => { d.open = true; });
|
|
64
|
+
};
|
|
65
|
+
initHubFilters();
|
|
66
|
+
openMap();
|
|
67
|
+
document.addEventListener('astro:page-load', () => { initHubFilters(); openMap(); });
|
|
68
|
+
</script>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// NeighborhoodHubPage's best-for filter: one Chip per value plus "all"; a press shows the rows (and locator points)
|
|
2
|
+
// carrying that value. Chip state is written as data-active="true|false" and aria-pressed, never as classes. The
|
|
3
|
+
// count line is re-announced through its aria-live region. Without this script every row stays visible and the
|
|
4
|
+
// filter group stays hidden.
|
|
5
|
+
import { fill } from '../internal/fill.ts';
|
|
6
|
+
|
|
7
|
+
export function rowMatches(tags: string, value: string): boolean {
|
|
8
|
+
return value === '' || tags.split('|').includes(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function countText(template: string, shown: number, total: number): string {
|
|
12
|
+
return fill(template, { shown, total });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function init(root: HTMLElement): void {
|
|
16
|
+
const chips = [...root.querySelectorAll<HTMLButtonElement>('[data-hub-filter]')];
|
|
17
|
+
const rows = [...root.querySelectorAll<HTMLElement>('[data-hub-row]')];
|
|
18
|
+
const points = [...root.querySelectorAll<SVGGElement>('[data-locator-point]')];
|
|
19
|
+
const status = root.querySelector<HTMLElement>('[data-hub-filter-status]');
|
|
20
|
+
const template = status?.dataset.template ?? '';
|
|
21
|
+
root.querySelector<HTMLElement>('[data-hub-filters]')?.removeAttribute('hidden');
|
|
22
|
+
const apply = (value: string) => {
|
|
23
|
+
chips.forEach((c) => {
|
|
24
|
+
const on = (c.dataset.hubFilter ?? '') === value;
|
|
25
|
+
c.dataset.active = String(on);
|
|
26
|
+
c.setAttribute('aria-pressed', String(on));
|
|
27
|
+
});
|
|
28
|
+
let shown = 0;
|
|
29
|
+
const visible = new Set<string>();
|
|
30
|
+
rows.forEach((r) => {
|
|
31
|
+
const ok = rowMatches(r.dataset.tags ?? '', value);
|
|
32
|
+
r.hidden = !ok;
|
|
33
|
+
if (ok) { shown++; visible.add(r.dataset.hubRow ?? ''); }
|
|
34
|
+
});
|
|
35
|
+
points.forEach((p) => p.classList.toggle('opacity-25', !visible.has(p.dataset.locatorPoint ?? '')));
|
|
36
|
+
if (status) status.textContent = countText(template, shown, rows.length);
|
|
37
|
+
};
|
|
38
|
+
chips.forEach((c) => c.addEventListener('click', () => apply(c.dataset.hubFilter ?? '')));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function initHubFilters(): void {
|
|
42
|
+
document.querySelectorAll<HTMLElement>('[data-hub]:not([data-hub-ready])').forEach((root) => {
|
|
43
|
+
root.setAttribute('data-hub-ready', '');
|
|
44
|
+
init(root);
|
|
45
|
+
});
|
|
46
|
+
}
|
package/src/templates/index.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// Public surface of @sarimarcus/content-sites-tourism/templates.
|
|
2
2
|
export { default as NeighborhoodFacetPage } from './NeighborhoodFacetPage.astro';
|
|
3
|
+
export { default as NeighborhoodDetailPage } from './NeighborhoodDetailPage.astro';
|
|
4
|
+
export { default as NeighborhoodHubPage } from './NeighborhoodHubPage.astro';
|
|
5
|
+
export { rowMatches, countText } from './hubFilter.ts';
|
|
3
6
|
export { default as ProximityFacetPage } from './ProximityFacetPage.astro';
|
|
4
7
|
export { default as TierFacetPage } from './TierFacetPage.astro';
|
|
5
8
|
export { default as CategoryFacetPage } from './CategoryFacetPage.astro';
|
|
6
9
|
export type { FacetEmptyState, FacetLink, FacetNav, FacetNavItem } from './facet';
|
|
7
10
|
export type { NeighborhoodFacetTone } from './NeighborhoodFacetPage.astro';
|
|
11
|
+
export type { DetailShelf, DetailFigure, DetailTip, DetailSiblings } from './NeighborhoodDetailPage.astro';
|
|
8
12
|
export type { ProximityIntroSection, ProximityEditorialGroup } from './ProximityFacetPage.astro';
|
|
9
13
|
export type { TierFacetTone, TierNav, TierNavItem } from './TierFacetPage.astro';
|
|
10
14
|
export type { CategoryFacetTone } from './CategoryFacetPage.astro';
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// The neighbourhood fields (SLA-3447) a site's collection spreads into its schema, the ids the hub and detail sections
|
|
2
|
+
// render, and the pure caps, picks and locator helpers. Public through ./neighborhoods.ts.
|
|
3
|
+
import type { z as Zod } from 'astro/zod';
|
|
4
|
+
import { haversineMetres } from '@sarimarcus/content-sites-core/geo';
|
|
5
|
+
import type { FacetNavItem } from './facet.ts';
|
|
6
|
+
import { LABELS } from '../internal/labels.ts';
|
|
7
|
+
|
|
8
|
+
/** `areaType`, not `category`: guide and listing code reads any item's `category` as a display label. */
|
|
9
|
+
export const NEIGHBORHOOD_CATEGORIES = ['historic', 'authentic', 'modern'] as const;
|
|
10
|
+
export type NeighborhoodCategory = (typeof NEIGHBORHOOD_CATEGORIES)[number];
|
|
11
|
+
|
|
12
|
+
export const NEIGHBORHOOD_BADGES = ['editors-pick', 'hidden-gem', 'family-friendly', 'tourist-centre', 'nightlife'] as const;
|
|
13
|
+
export type NeighborhoodBadge = (typeof NEIGHBORHOOD_BADGES)[number];
|
|
14
|
+
|
|
15
|
+
/** Granada's pre-SLA-3447 badge ids, for the migration only. */
|
|
16
|
+
export const LEGACY_BADGE_IDS: Readonly<Record<string, NeighborhoodBadge>> = {
|
|
17
|
+
'coup-de-coeur': 'editors-pick',
|
|
18
|
+
'pepite-cachee': 'hidden-gem',
|
|
19
|
+
'ideal-familles': 'family-friendly',
|
|
20
|
+
'centre-touristique': 'tourist-centre',
|
|
21
|
+
'vie-nocturne': 'nightlife',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const BASE_VERDICT_MAX = 180;
|
|
25
|
+
export const PICKS_MAX = 3;
|
|
26
|
+
export const PICK_KINDS = ['stay', 'eat', 'see'] as const;
|
|
27
|
+
export type PickKind = (typeof PICK_KINDS)[number];
|
|
28
|
+
export type NeighborhoodPicks = Partial<Record<PickKind, string[]>>;
|
|
29
|
+
|
|
30
|
+
type ZodBuilders = Pick<typeof Zod, 'enum' | 'string' | 'array' | 'object'>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Optional `areaType`, `badge`, `baseVerdict` and `picks` for the neighborhoods collection's `z.object({...})`, built
|
|
34
|
+
* with the site's own `z`. `picks` holds item slugs (stay = hotels, eat = restaurants, see = monuments and museums);
|
|
35
|
+
* zod cannot see other collections, so the renderer drops a slug it cannot resolve and falls back.
|
|
36
|
+
*/
|
|
37
|
+
export function neighborhoodSchemaFields(z: ZodBuilders) {
|
|
38
|
+
const slugs = z.array(z.string().min(1)).max(PICKS_MAX).optional();
|
|
39
|
+
return {
|
|
40
|
+
areaType: z.enum(NEIGHBORHOOD_CATEGORIES).optional(),
|
|
41
|
+
badge: z.enum(NEIGHBORHOOD_BADGES).optional(),
|
|
42
|
+
baseVerdict: z.string().min(1).max(BASE_VERDICT_MAX).optional(),
|
|
43
|
+
picks: z.object({ stay: slugs, eat: slugs, see: slugs }).optional(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A neighbourhood facet page (/neighborhood/<slug>/<type>) exists from this many items. */
|
|
48
|
+
export const FACET_MIN_ITEMS = 5;
|
|
49
|
+
/** The neighbourhood facet routes, in chip order. */
|
|
50
|
+
export const FACET_TYPES = ['monuments', 'hotels', 'restaurants', 'bars', 'activities'] as const;
|
|
51
|
+
export type FacetType = (typeof FACET_TYPES)[number];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The sibling-facet chips of one neighbourhood: every facet type with FACET_MIN_ITEMS items or more (the ones that have
|
|
55
|
+
* a page), `current` marked active. `href` adds the site's base path (core `url`).
|
|
56
|
+
*/
|
|
57
|
+
export function neighborhoodFacetItems(
|
|
58
|
+
slug: string,
|
|
59
|
+
counts: Partial<Record<FacetType, number>>,
|
|
60
|
+
current: FacetType,
|
|
61
|
+
href: (path: string) => string,
|
|
62
|
+
labels: Record<string, string> = LABELS.neighborhoodFacets,
|
|
63
|
+
): FacetNavItem[] {
|
|
64
|
+
return FACET_TYPES.filter((t) => (counts[t] ?? 0) >= FACET_MIN_ITEMS).map((t) => ({
|
|
65
|
+
href: href(`/neighborhood/${slug}/${t}`),
|
|
66
|
+
label: labels[t] ?? t,
|
|
67
|
+
count: counts[t] ?? 0,
|
|
68
|
+
active: t === current,
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Items per facet type in one neighbourhood, from the site's `getCollection`. */
|
|
73
|
+
export async function neighborhoodFacetCounts(
|
|
74
|
+
slug: string,
|
|
75
|
+
getCollection: (type: FacetType) => Promise<readonly { data: { neighborhood?: string | null } }[]>,
|
|
76
|
+
): Promise<Record<FacetType, number>> {
|
|
77
|
+
const entries = await Promise.all(FACET_TYPES.map(async (t) => [t, (await getCollection(t)).filter((i) => i.data.neighborhood === slug).length] as const));
|
|
78
|
+
return Object.fromEntries(entries) as Record<FacetType, number>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Items a detail-page shelf shows when the rest live on a facet page. */
|
|
82
|
+
export const SHELF_PREVIEW = 4;
|
|
83
|
+
|
|
84
|
+
/** Fewer than FACET_MIN_ITEMS: show them all. Otherwise SHELF_PREVIEW items and a link to the facet. */
|
|
85
|
+
export function shelfPlan(count: number, hasFacetRoute = true): { show: number; linkFacet: boolean } {
|
|
86
|
+
const linkFacet = hasFacetRoute && count >= FACET_MIN_ITEMS;
|
|
87
|
+
return { show: linkFacet ? SHELF_PREVIEW : count, linkFacet };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface LatLng { lat: number; lng: number }
|
|
91
|
+
export interface LocatorInput { slug: string; points: readonly LatLng[] }
|
|
92
|
+
export interface LocatorPoint { slug: string; x: number; y: number; km: number }
|
|
93
|
+
export interface LocatorLayout { width: number; height: number; anchor: { x: number; y: number }; points: LocatorPoint[] }
|
|
94
|
+
|
|
95
|
+
/** The centre of an item set, or null with no points. */
|
|
96
|
+
export function centroid(points: readonly LatLng[]): LatLng | null {
|
|
97
|
+
if (!points.length) return null;
|
|
98
|
+
return { lat: points.reduce((a, p) => a + p.lat, 0) / points.length, lng: points.reduce((a, p) => a + p.lng, 0) / points.length };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Straight-line distance in km, one decimal. */
|
|
102
|
+
export function distanceKm(a: LatLng, b: LatLng): number {
|
|
103
|
+
return Math.round(haversineMetres(a.lat, a.lng, b.lat, b.lng) / 100) / 10;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Positions for the hub's locator SVG. Each neighbourhood sits at the centroid of its items, pulled towards the anchor
|
|
108
|
+
* landmark by a square-root of its distance so the central cluster separates (not to scale: `km` keeps the true
|
|
109
|
+
* distance), then nudged apart until no two points are closer than `minGap`. Neighbourhoods without points are left out.
|
|
110
|
+
*/
|
|
111
|
+
export function locatorPoints(
|
|
112
|
+
hoods: readonly LocatorInput[],
|
|
113
|
+
anchorAt: LatLng,
|
|
114
|
+
{ width = 320, height = 260, pad = 30, minGap = 24 } = {},
|
|
115
|
+
): LocatorLayout {
|
|
116
|
+
const placed = hoods.flatMap((h) => {
|
|
117
|
+
const c = centroid(h.points);
|
|
118
|
+
if (!c) return [];
|
|
119
|
+
const dy = c.lat - anchorAt.lat, dx = c.lng - anchorAt.lng, r = Math.hypot(dx, dy);
|
|
120
|
+
const s = r ? (Math.sqrt(r) * 0.06) / r : 0;
|
|
121
|
+
return [{ slug: h.slug, km: distanceKm(c, anchorAt), at: { lat: anchorAt.lat + dy * s, lng: anchorAt.lng + dx * s } }];
|
|
122
|
+
});
|
|
123
|
+
const all = [...placed.map((p) => p.at), anchorAt];
|
|
124
|
+
const k = Math.cos(((all.reduce((a, p) => a + p.lat, 0) / all.length) * Math.PI) / 180);
|
|
125
|
+
const xs = all.map((p) => p.lng * k), ys = all.map((p) => -p.lat);
|
|
126
|
+
const [x0, x1, y0, y1] = [Math.min(...xs), Math.max(...xs), Math.min(...ys), Math.max(...ys)];
|
|
127
|
+
const span = Math.max(x1 - x0, 1e-9), spanY = Math.max(y1 - y0, 1e-9);
|
|
128
|
+
const scale = Math.min((width - 2 * pad) / span, (height - 2 * pad) / spanY);
|
|
129
|
+
const ox = pad + (width - 2 * pad - span * scale) / 2, oy = pad + (height - 2 * pad - spanY * scale) / 2;
|
|
130
|
+
const project = (p: LatLng) => ({ x: ox + (p.lng * k - x0) * scale, y: oy + (-p.lat - y0) * scale });
|
|
131
|
+
const pts = placed.map((p) => ({ slug: p.slug, km: p.km, ...project(p.at) }));
|
|
132
|
+
for (let it = 0; it < 40; it++) {
|
|
133
|
+
for (let i = 0; i < pts.length; i++) for (let j = i + 1; j < pts.length; j++) {
|
|
134
|
+
const a = pts[i], b = pts[j], dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy) || 1;
|
|
135
|
+
if (d < minGap) { const m = (minGap - d) / 2, ux = dx / d, uy = dy / d; a.x -= ux * m; a.y -= uy * m; b.x += ux * m; b.y += uy * m; }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const lo = minGap / 2;
|
|
139
|
+
for (const p of pts) { p.x = Math.min(width - lo, Math.max(lo, p.x)); p.y = Math.min(height - lo, Math.max(lo, p.y)); }
|
|
140
|
+
const round = (v: number) => Math.round(v * 10) / 10;
|
|
141
|
+
return { width, height, anchor: (({ x, y }) => ({ x: round(x), y: round(y) }))(project(anchorAt)), points: pts.map((p) => ({ ...p, x: round(p.x), y: round(p.y) })) };
|
|
142
|
+
}
|
|
143
|
+
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// The data models behind NeighborhoodDetailPage and NeighborhoodHubPage (SLA-3448/3449). Pure: a route loads its
|
|
2
|
+
// collections, maps each entry to a NeighborhoodItem (its own field names, its own image map), and passes the result
|
|
3
|
+
// here; everything the two sites must agree on (ranking, caps, picks, hub order, locator numbers, labels) lives here
|
|
4
|
+
// once. English strings come from LABELS and can be overridden per call.
|
|
5
|
+
import type { ImageMetadata } from 'astro';
|
|
6
|
+
import { parseMarkdownInline, stripMarkdown } from '@sarimarcus/content-sites-core/text';
|
|
7
|
+
import { textAsHtml, trustedHtml } from '@sarimarcus/content-sites-ui/types';
|
|
8
|
+
import type { TrustedHtml } from '@sarimarcus/content-sites-ui/types';
|
|
9
|
+
import { LABELS } from '../internal/labels.ts';
|
|
10
|
+
import { fill } from '../internal/fill.ts';
|
|
11
|
+
import {
|
|
12
|
+
FACET_MIN_ITEMS, PICKS_MAX, centroid, distanceKm, locatorPoints, shelfPlan,
|
|
13
|
+
type LatLng, type LocatorLayout, type NeighborhoodPicks,
|
|
14
|
+
} from './neighborhoodCore.ts';
|
|
15
|
+
|
|
16
|
+
export type ItemType = 'monuments' | 'museums' | 'restaurants' | 'bars' | 'hotels' | 'activities' | 'walks' | 'events';
|
|
17
|
+
|
|
18
|
+
export interface NeighborhoodItem {
|
|
19
|
+
type: ItemType;
|
|
20
|
+
slug: string;
|
|
21
|
+
name: string;
|
|
22
|
+
/** Site-relative item URL with the base path already applied. */
|
|
23
|
+
href: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
featured?: boolean;
|
|
26
|
+
rating?: number | null;
|
|
27
|
+
at?: LatLng | null;
|
|
28
|
+
image?: ImageMetadata;
|
|
29
|
+
fallbackSrc: string;
|
|
30
|
+
imageAlt?: string;
|
|
31
|
+
priceRange?: string;
|
|
32
|
+
cuisine?: string;
|
|
33
|
+
duration?: string;
|
|
34
|
+
price?: string;
|
|
35
|
+
distance?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type NeighborhoodItems = Record<ItemType, NeighborhoodItem[]>;
|
|
39
|
+
|
|
40
|
+
export interface HoodSummary {
|
|
41
|
+
slug: string;
|
|
42
|
+
name: string;
|
|
43
|
+
href: string;
|
|
44
|
+
image?: ImageMetadata;
|
|
45
|
+
fallbackSrc: string;
|
|
46
|
+
imageAlt?: string;
|
|
47
|
+
/** Coordinates of its monuments, museums, restaurants and hotels. */
|
|
48
|
+
points: LatLng[];
|
|
49
|
+
hotels: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Anchor { label: string; at: LatLng | null }
|
|
53
|
+
|
|
54
|
+
type Labels = typeof LABELS.neighborhoodModel;
|
|
55
|
+
const plural = (n: number, [one, many]: readonly [string, string]) => `${n} ${n === 1 ? one : many}`;
|
|
56
|
+
const firstSentence = (t?: string) => { const s = stripMarkdown(t ?? ''); const m = s.match(/^.*?[.!?](\s|$)/); return (m ? m[0] : s).trim(); };
|
|
57
|
+
const firstClause = (t?: string) => (t ? t.split(/[.(;]/)[0].trim() : '');
|
|
58
|
+
const label = (v: string) => v.replace(/-/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
59
|
+
|
|
60
|
+
/** A rating that may be stored as a number or as `{ score }`. */
|
|
61
|
+
export function ratingValue(r: unknown): number | null {
|
|
62
|
+
if (typeof r === 'number') return r;
|
|
63
|
+
if (r && typeof r === 'object' && typeof (r as { score?: unknown }).score === 'number') return (r as { score: number }).score;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `{lat,lng}` or `{latitude,longitude}`, or null. */
|
|
68
|
+
export function toLatLng(c: { lat?: number; lng?: number; latitude?: number; longitude?: number } | null | undefined): LatLng | null {
|
|
69
|
+
const lat = c?.lat ?? c?.latitude, lng = c?.lng ?? c?.longitude;
|
|
70
|
+
return typeof lat === 'number' && typeof lng === 'number' ? { lat, lng } : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The one ranking for shelves and pick columns: featured, then rating high to low when `rated`, then name. */
|
|
74
|
+
export function rankItems<T extends { name: string; featured?: boolean; rating?: number | null }>(items: readonly T[], { rated = true } = {}): T[] {
|
|
75
|
+
return [...items].sort((a, b) => Number(!!b.featured) - Number(!!a.featured) || (rated ? (b.rating ?? 0) - (a.rating ?? 0) : 0) || a.name.localeCompare(b.name));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Up to PICKS_MAX items: the editor's slugs first (unknown ones dropped), then `rankItems`. */
|
|
79
|
+
export function resolvePicks<T extends { slug: string; name: string; featured?: boolean; rating?: number | null }>(slugs: readonly string[] | undefined, items: readonly T[], { rated = true } = {}): T[] {
|
|
80
|
+
const bySlug = new Map(items.map((i) => [i.slug, i]));
|
|
81
|
+
const chosen: T[] = [];
|
|
82
|
+
for (const s of slugs ?? []) { const hit = bySlug.get(s); if (hit && !chosen.includes(hit)) chosen.push(hit); }
|
|
83
|
+
return [...chosen, ...rankItems(items.filter((i) => !chosen.includes(i)), { rated })].slice(0, PICKS_MAX);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The hub's order, which also numbers the locator points on every page: most hotels, then nearest the anchor, then name. */
|
|
87
|
+
export function hubOrder<T extends HoodSummary>(hoods: readonly T[], anchor: Anchor): T[] {
|
|
88
|
+
const km = new Map(hoods.map((h) => { const c = centroid(h.points); return [h, c && anchor.at ? distanceKm(c, anchor.at) : 99] as const; }));
|
|
89
|
+
return [...hoods].sort((a, b) => b.hotels - a.hotels || km.get(a)! - km.get(b)! || a.name.localeCompare(b.name));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function kmLabel(km: number, anchor: Anchor, L: Labels) {
|
|
93
|
+
return km < 0.1 ? fill(L.beside, { anchor: anchor.label }) : fill(L.kmFrom, { km: km.toFixed(1), anchor: anchor.label });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A pin for the site's live map, in the shape its map component takes; `order` is the number in the hub list. */
|
|
97
|
+
export interface LocatorStop { order: number; name: string; coordinates: LatLng; type: 'neighborhood'; slug: string; active?: boolean }
|
|
98
|
+
|
|
99
|
+
/** `order` is hubOrder's output: the map numbers what the hub list numbers. */
|
|
100
|
+
function locatorFor(order: readonly HoodSummary[], anchor: Anchor) {
|
|
101
|
+
if (!anchor.at) return undefined;
|
|
102
|
+
return {
|
|
103
|
+
layout: locatorPoints(order.map((h) => ({ slug: h.slug, points: h.points })), anchor.at) as LocatorLayout,
|
|
104
|
+
numbers: Object.fromEntries(order.map((h, i) => [h.slug, i + 1])),
|
|
105
|
+
names: Object.fromEntries(order.map((h) => [h.slug, h.name])),
|
|
106
|
+
stops: order.flatMap((h, i): LocatorStop[] => {
|
|
107
|
+
const c = centroid(h.points);
|
|
108
|
+
return c ? [{ order: i + 1, name: h.name, coordinates: c, type: 'neighborhood', slug: h.slug }] : [];
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface DetailModelInput {
|
|
114
|
+
hood: {
|
|
115
|
+
slug: string; name: string; description: string; baseVerdict?: string;
|
|
116
|
+
audiences?: readonly string[]; themes?: readonly string[]; picks?: NeighborhoodPicks;
|
|
117
|
+
sectionIntros?: Partial<Record<'monuments' | 'restaurants' | 'bars' | 'hotels' | 'activities', string>>;
|
|
118
|
+
insiderTips?: readonly (string | { title?: string; body?: string })[];
|
|
119
|
+
};
|
|
120
|
+
items: NeighborhoodItems;
|
|
121
|
+
hoods: readonly HoodSummary[];
|
|
122
|
+
anchor: Anchor;
|
|
123
|
+
city: string;
|
|
124
|
+
/** Site URL builder (core `url`), for facet links and the hub. */
|
|
125
|
+
url: (path: string) => string;
|
|
126
|
+
/** Fallback image when a figure has none. */
|
|
127
|
+
placeholder: string;
|
|
128
|
+
/** An external map search for this neighbourhood (the site builds it: host and place query are its own). */
|
|
129
|
+
mapsLink?: { href: string; label?: string };
|
|
130
|
+
basePath?: string;
|
|
131
|
+
/** Cap the sibling strip (Granada: 6, for its closer's tail-link budget). */
|
|
132
|
+
siblingsCap?: number;
|
|
133
|
+
labels?: Partial<Labels>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function neighborhoodDetailModel(input: DetailModelInput) {
|
|
137
|
+
const L: Labels = { ...LABELS.neighborhoodModel, ...input.labels };
|
|
138
|
+
const { hood, items, anchor, url } = input;
|
|
139
|
+
const n = Object.fromEntries(Object.entries(items).map(([k, v]) => [k, v.length])) as Record<ItemType, number>;
|
|
140
|
+
const intro = (t?: string) => (t ? trustedHtml(parseMarkdownInline(t, input.basePath)) : undefined);
|
|
141
|
+
const facet = (type: string, count: number, noun: readonly [string, string]) =>
|
|
142
|
+
count >= FACET_MIN_ITEMS ? { href: url(`/neighborhood/${hood.slug}/${type}`), label: fill(L.allIn, { count, noun: noun[1], name: hood.name }) } : undefined;
|
|
143
|
+
const km = (i: NeighborhoodItem) => (i.at && anchor.at ? kmLabel(distanceKm(i.at, anchor.at), anchor, L) : '');
|
|
144
|
+
const rating = (i: NeighborhoodItem) => (i.rating ? `★ ${i.rating.toFixed(1)}` : '');
|
|
145
|
+
const card = (i: NeighborhoodItem, extra: { meta?: string[]; description?: string } = {}) => ({
|
|
146
|
+
href: i.href, name: i.name, image: i.image, fallbackSrc: i.fallbackSrc, imageAlt: i.imageAlt ?? i.name,
|
|
147
|
+
...(extra.meta ? { meta: extra.meta.filter(Boolean) } : {}), ...(extra.description ? { description: extra.description } : {}),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const sights = [...items.monuments, ...items.museums];
|
|
151
|
+
const seePlan = shelfPlan(sights.length, n.monuments >= FACET_MIN_ITEMS);
|
|
152
|
+
const shelves = [
|
|
153
|
+
{ id: 'see', heading: L.see, layout: 'feature' as const, introHtml: intro(hood.sectionIntros?.monuments), facetLink: facet('monuments', n.monuments, L.monument),
|
|
154
|
+
items: sights.slice(0, seePlan.show).map((i) => card(i, { description: firstSentence(i.description) })) },
|
|
155
|
+
{ id: 'stay', heading: L.stay, layout: 'row' as const, introHtml: intro(hood.sectionIntros?.hotels), facetLink: facet('hotels', n.hotels, L.hotel),
|
|
156
|
+
items: rankItems(items.hotels).slice(0, shelfPlan(n.hotels).show).map((i) => card(i, { meta: [i.priceRange ?? '', rating(i), km(i)], description: firstSentence(i.description) })) },
|
|
157
|
+
{ id: 'eat', heading: L.eat, layout: 'tile' as const, introHtml: intro(hood.sectionIntros?.restaurants), facetLink: facet('restaurants', n.restaurants, L.restaurant),
|
|
158
|
+
items: rankItems(items.restaurants).slice(0, shelfPlan(n.restaurants).show).map((i) => card(i, { meta: [i.cuisine ?? '', rating(i)] })) },
|
|
159
|
+
{ id: 'drink', heading: L.drink, layout: 'thumb' as const, introHtml: intro(hood.sectionIntros?.bars), facetLink: facet('bars', n.bars, L.bar),
|
|
160
|
+
items: rankItems(items.bars).slice(0, shelfPlan(n.bars).show).map((i) => card(i)) },
|
|
161
|
+
{ id: 'do', heading: L.do, layout: 'row' as const, introHtml: intro(hood.sectionIntros?.activities), facetLink: facet('activities', n.activities, L.activity),
|
|
162
|
+
items: items.activities.slice(0, shelfPlan(n.activities).show).map((i) => card(i, { meta: [firstClause(i.duration), firstClause(i.price)] })) },
|
|
163
|
+
{ id: 'walk', heading: L.walk, layout: 'strip' as const, pagefindIgnore: true,
|
|
164
|
+
items: items.walks.map((i) => card(i, { meta: [i.distance ?? '', i.duration ?? ''] })) },
|
|
165
|
+
{ id: 'events', heading: fill(L.eventsIn, { name: hood.name }), layout: 'strip' as const, items: items.events.map((i) => card(i)) },
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
const centre = centroid([...items.monuments, ...items.museums, ...items.restaurants, ...items.hotels].flatMap((i) => (i.at ? [i.at] : [])));
|
|
169
|
+
const note = (i: NeighborhoodItem) => (i.rating ? `★ ${i.rating.toFixed(1)}` : undefined);
|
|
170
|
+
const pickCol = (heading: string, icon: string, picked: NeighborhoodItem[], allLink?: { href: string; label: string }) =>
|
|
171
|
+
({ heading, icon, items: picked.map((p) => ({ href: p.href, name: p.name, note: note(p) })), allLink });
|
|
172
|
+
const base = {
|
|
173
|
+
heading: fill(L.baseHeading, { name: hood.name }),
|
|
174
|
+
verdictHtml: textAsHtml(hood.baseVerdict ?? hood.description) as TrustedHtml,
|
|
175
|
+
tags: [...(hood.audiences ?? []), ...(hood.themes ?? [])].map(label),
|
|
176
|
+
facts: [
|
|
177
|
+
...(centre && anchor.at ? [{ icon: 'map-pin', label: kmLabel(distanceKm(centre, anchor.at), anchor, L) }] : []),
|
|
178
|
+
{ icon: 'bed-double', label: n.hotels ? plural(n.hotels, L.hotel) : L.noHotels },
|
|
179
|
+
...(n.restaurants ? [{ icon: 'utensils', label: plural(n.restaurants, L.restaurant) }] : []),
|
|
180
|
+
...(n.monuments ? [{ icon: 'landmark', label: plural(n.monuments, L.monument) + (n.museums ? `, ${plural(n.museums, L.museum)}` : '') }] : []),
|
|
181
|
+
],
|
|
182
|
+
mapLink: { href: '#map', label: L.openMap },
|
|
183
|
+
columns: [
|
|
184
|
+
pickCol(L.stay, 'bed-double', resolvePicks(hood.picks?.stay, items.hotels), facet('hotels', n.hotels, L.hotel)),
|
|
185
|
+
pickCol(L.eat, 'utensils', resolvePicks(hood.picks?.eat, items.restaurants), facet('restaurants', n.restaurants, L.restaurant)),
|
|
186
|
+
pickCol(L.see, 'landmark', resolvePicks(hood.picks?.see, sights, { rated: false }), facet('monuments', n.monuments, L.monument)),
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const shown = new Set(shelves.flatMap((s) => s.items.map((i) => i.href)));
|
|
191
|
+
const figure = (cands: NeighborhoodItem[]) => {
|
|
192
|
+
const hit = cands.find((c) => !shown.has(c.href) && c.image);
|
|
193
|
+
if (!hit) return undefined;
|
|
194
|
+
shown.add(hit.href);
|
|
195
|
+
return { image: hit.image, fallbackSrc: input.placeholder, alt: hit.imageAlt ?? hit.name, caption: hit.name };
|
|
196
|
+
};
|
|
197
|
+
const bodyFigure = figure(sights);
|
|
198
|
+
const tipsFigure = figure([...sights, ...items.restaurants]);
|
|
199
|
+
const tipItems = (hood.insiderTips ?? []).map((t) => (typeof t === 'string' ? { body: stripMarkdown(t) } : { title: t.title, body: stripMarkdown(t.body ?? '') }));
|
|
200
|
+
|
|
201
|
+
const loc = locatorFor(hubOrder(input.hoods, anchor), anchor);
|
|
202
|
+
const locator = loc && {
|
|
203
|
+
...loc,
|
|
204
|
+
stops: loc.stops.map((s) => (s.slug === hood.slug ? { ...s, active: true } : s)),
|
|
205
|
+
anchorLabel: anchor.label,
|
|
206
|
+
ariaLabel: fill(L.detailMapAria, { city: input.city, name: hood.name, anchor: anchor.label }),
|
|
207
|
+
caption: fill(L.detailMapCaption, { name: hood.name }),
|
|
208
|
+
liveCaption: fill(L.detailLiveMapCaption, { name: hood.name }),
|
|
209
|
+
mapLink: input.mapsLink && { href: input.mapsLink.href, label: input.mapsLink.label ?? L.googleMaps },
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const others = input.hoods.filter((h) => h.slug !== hood.slug);
|
|
213
|
+
const siblings = {
|
|
214
|
+
label: L.siblingsLabel, ariaLabel: L.otherHoods,
|
|
215
|
+
items: others.slice(0, input.siblingsCap ?? others.length).map((h) => ({ href: h.href, name: h.name })),
|
|
216
|
+
all: { href: url('/neighborhoods'), label: L.allHoods },
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
base, shelves, bodyFigure, locator, siblings,
|
|
221
|
+
tips: tipItems.length ? { heading: L.insiderTips, items: tipItems, figure: tipsFigure } : undefined,
|
|
222
|
+
/** Every item href the page renders, for the closer's `buildTakenHrefs`. */
|
|
223
|
+
renderedHrefs: [...base.columns.flatMap((c) => c.items.map((i) => i.href)), ...shown, ...siblings.items.map((i) => i.href)],
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface HubModelInput {
|
|
228
|
+
hoods: readonly (HoodSummary & {
|
|
229
|
+
restaurants: number; sights: number; areaType?: string; badge?: string;
|
|
230
|
+
baseVerdict?: string; atmosphere?: string; audiences?: readonly string[]; themes?: readonly string[];
|
|
231
|
+
})[];
|
|
232
|
+
anchor: Anchor;
|
|
233
|
+
city: string;
|
|
234
|
+
url: (path: string) => string;
|
|
235
|
+
/** Defaults: LABELS.neighborhoodAreaTypes / neighborhoodBadges. */
|
|
236
|
+
areaLabels?: Record<string, string>;
|
|
237
|
+
badgeLabels?: Record<string, string>;
|
|
238
|
+
labels?: Partial<Labels>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Filters: values held by at least two neighbourhoods and not by all but one, most discriminating (closest to half) first, at most three. */
|
|
242
|
+
export function hubFilters(valueSets: readonly (readonly string[])[], max = 3): { value: string; label: string }[] {
|
|
243
|
+
const total = valueSets.length;
|
|
244
|
+
const counts = new Map<string, number>();
|
|
245
|
+
for (const vs of valueSets) for (const v of new Set(vs)) counts.set(v, (counts.get(v) ?? 0) + 1);
|
|
246
|
+
return [...counts]
|
|
247
|
+
.filter(([, c]) => c >= 2 && c <= Math.max(2, total - 2))
|
|
248
|
+
.sort((a, b) => Math.abs(a[1] - total / 2) - Math.abs(b[1] - total / 2) || b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
249
|
+
.slice(0, max)
|
|
250
|
+
.map(([value]) => ({ value, label: label(value) }));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function neighborhoodHubModel(input: HubModelInput) {
|
|
254
|
+
const L: Labels = { ...LABELS.neighborhoodModel, ...input.labels };
|
|
255
|
+
const { anchor } = input;
|
|
256
|
+
const areaLabels = input.areaLabels ?? LABELS.neighborhoodAreaTypes;
|
|
257
|
+
const badgeLabels = input.badgeLabels ?? LABELS.neighborhoodBadges;
|
|
258
|
+
const order = hubOrder(input.hoods, anchor);
|
|
259
|
+
const rows = order.map((h, i) => {
|
|
260
|
+
const values = [...(h.audiences ?? []), ...(h.themes ?? [])];
|
|
261
|
+
const c = centroid(h.points);
|
|
262
|
+
const km = c && anchor.at ? distanceKm(c, anchor.at) : null;
|
|
263
|
+
return {
|
|
264
|
+
slug: h.slug, number: i + 1, name: h.name, href: h.href,
|
|
265
|
+
areaLabel: h.areaType ? areaLabels[h.areaType] : undefined,
|
|
266
|
+
verdict: h.baseVerdict ?? h.atmosphere,
|
|
267
|
+
tags: [...(h.badge && badgeLabels[h.badge] ? [badgeLabels[h.badge]] : []), ...values.map(label)],
|
|
268
|
+
filterValues: values,
|
|
269
|
+
facts: [
|
|
270
|
+
{ icon: 'bed-double', label: h.hotels ? plural(h.hotels, L.hotel) : L.noHotels },
|
|
271
|
+
...(h.restaurants ? [{ icon: 'utensils', label: plural(h.restaurants, L.restaurant) }] : []),
|
|
272
|
+
...(h.sights ? [{ icon: 'landmark', label: plural(h.sights, L.sight) }] : []),
|
|
273
|
+
...(km !== null ? [{ icon: 'map-pin', label: kmLabel(km, anchor, L) }] : []),
|
|
274
|
+
],
|
|
275
|
+
exploreLabel: fill(L.explore, { name: h.name }),
|
|
276
|
+
hotelsLink: h.hotels >= FACET_MIN_ITEMS ? { href: input.url(`/neighborhood/${h.slug}/hotels`), label: fill(L.seeHotels, { count: h.hotels }) } : undefined,
|
|
277
|
+
image: h.image, fallbackSrc: h.fallbackSrc, imageAlt: h.imageAlt ?? h.name,
|
|
278
|
+
eager: i < 3,
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
const loc = locatorFor(order, anchor);
|
|
282
|
+
return {
|
|
283
|
+
heading: fill(L.hubHeading, { city: input.city }),
|
|
284
|
+
standfirst: fill(L.hubStandfirst, { count: rows.length, anchor: anchor.label }),
|
|
285
|
+
filters: hubFilters(rows.map((r) => r.filterValues)),
|
|
286
|
+
allLabel: L.allAreas,
|
|
287
|
+
filterAriaLabel: L.filterAria,
|
|
288
|
+
statusTemplate: L.status,
|
|
289
|
+
total: rows.length,
|
|
290
|
+
rows,
|
|
291
|
+
map: loc && {
|
|
292
|
+
...loc,
|
|
293
|
+
anchorLabel: anchor.label,
|
|
294
|
+
ariaLabel: fill(L.hubMapAria, { city: input.city, count: rows.length, anchor: anchor.label }),
|
|
295
|
+
summary: fill(L.hubMapSummary, { count: rows.length }),
|
|
296
|
+
note: fill(L.hubMapNote, { anchor: anchor.label }),
|
|
297
|
+
liveNote: L.hubLiveMapNote,
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Each item type's detail route (`/<route>/<slug>`), also its placeholder kind. */
|
|
303
|
+
export const ITEM_ROUTES: Readonly<Record<ItemType, string>> = {
|
|
304
|
+
monuments: 'monument', museums: 'museum', restaurants: 'restaurant', bars: 'bar', hotels: 'hotel', activities: 'activity', walks: 'walk', events: 'event',
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
type EntryData = { slug: string; name: string; [k: string]: unknown };
|
|
308
|
+
export interface EntryLike { data: EntryData }
|
|
309
|
+
/** The hub needs only neighborhoods, monuments, museums, restaurants and hotels; the rest default to empty. */
|
|
310
|
+
export type NeighborhoodCollections = Record<'neighborhoods' | 'monuments' | 'museums' | 'restaurants' | 'hotels', readonly EntryLike[]>
|
|
311
|
+
& Partial<Record<'bars' | 'activities' | 'walks' | 'events', readonly EntryLike[]>>;
|
|
312
|
+
|
|
313
|
+
export interface DataOptions {
|
|
314
|
+
url: (path: string) => string;
|
|
315
|
+
/** Per type: eager image map keyed by file basename (core `buildImageMap`). */
|
|
316
|
+
images: Partial<Record<ItemType | 'neighborhoods', Record<string, ImageMetadata>>>;
|
|
317
|
+
/** The site's placeholder for a kind ('neighborhood', 'monument', …). */
|
|
318
|
+
placeholder: (kind: string) => string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const str = (v: unknown) => (typeof v === 'string' ? v : undefined);
|
|
322
|
+
const inHood = (slug: string) => (e: EntryLike) => e.data.neighborhood === slug;
|
|
323
|
+
const inHoods = (slug: string) => (e: EntryLike) => Array.isArray(e.data.neighborhoods) && (e.data.neighborhoods as unknown[]).includes(slug);
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* A site's collections as the two models take them: `hoods` (every neighbourhood with its locator points and counts, as
|
|
327
|
+
* the hub and every detail page must compute them alike) and `itemsFor(slug)`. Items match on `neighborhood`, walks and
|
|
328
|
+
* events on `neighborhoods[]`. Images resolve by the file basename of `image`, then by slug.
|
|
329
|
+
*/
|
|
330
|
+
export function neighborhoodData(collections: NeighborhoodCollections, { url, images, placeholder }: DataOptions) {
|
|
331
|
+
const c = { bars: [], activities: [], walks: [], events: [], ...collections };
|
|
332
|
+
const imageOf = (type: ItemType | 'neighborhoods', d: EntryData) => {
|
|
333
|
+
const map = images[type] ?? {};
|
|
334
|
+
const key = str(d.image)?.split('/').pop()?.replace(/\.(webp|jpe?g|png)$/i, '');
|
|
335
|
+
return (key && map[key]) || map[d.slug];
|
|
336
|
+
};
|
|
337
|
+
const item = (type: ItemType, d: EntryData): NeighborhoodItem => ({
|
|
338
|
+
type, slug: d.slug, name: d.name, href: url(`/${ITEM_ROUTES[type]}/${d.slug}`), description: str(d.description),
|
|
339
|
+
featured: d.featured === true, rating: ratingValue(d.rating), at: toLatLng(d.coordinates as Parameters<typeof toLatLng>[0]),
|
|
340
|
+
image: imageOf(type, d), fallbackSrc: placeholder(ITEM_ROUTES[type]), imageAlt: str(d.imageAlt), priceRange: str(d.priceRange),
|
|
341
|
+
cuisine: str(d.cuisine), duration: str(d.duration), price: str(d.price), distance: str(d.distance),
|
|
342
|
+
});
|
|
343
|
+
const itemsFor = (slug: string): NeighborhoodItems => ({
|
|
344
|
+
monuments: c.monuments.filter(inHood(slug)).map((e) => item('monuments', e.data)),
|
|
345
|
+
museums: c.museums.filter(inHood(slug)).map((e) => item('museums', e.data)),
|
|
346
|
+
restaurants: c.restaurants.filter(inHood(slug)).map((e) => item('restaurants', e.data)),
|
|
347
|
+
bars: c.bars.filter(inHood(slug)).map((e) => item('bars', e.data)),
|
|
348
|
+
hotels: c.hotels.filter(inHood(slug)).map((e) => item('hotels', e.data)),
|
|
349
|
+
activities: c.activities.filter(inHood(slug)).map((e) => item('activities', e.data)),
|
|
350
|
+
walks: c.walks.filter(inHoods(slug)).map((e) => item('walks', e.data)),
|
|
351
|
+
events: c.events.filter(inHoods(slug)).map((e) => item('events', e.data)),
|
|
352
|
+
});
|
|
353
|
+
const placed = [...c.monuments, ...c.museums, ...c.restaurants, ...c.hotels];
|
|
354
|
+
const hoods = c.neighborhoods.map((n) => {
|
|
355
|
+
const d = n.data;
|
|
356
|
+
return {
|
|
357
|
+
slug: d.slug, name: d.name, href: url(`/neighborhood/${d.slug}`), image: imageOf('neighborhoods', d),
|
|
358
|
+
fallbackSrc: placeholder('neighborhood'), imageAlt: str(d.imageAlt),
|
|
359
|
+
points: placed.filter(inHood(d.slug)).flatMap((e) => { const p = toLatLng(e.data.coordinates as Parameters<typeof toLatLng>[0]); return p ? [p] : []; }),
|
|
360
|
+
hotels: c.hotels.filter(inHood(d.slug)).length,
|
|
361
|
+
restaurants: c.restaurants.filter(inHood(d.slug)).length,
|
|
362
|
+
sights: c.monuments.filter(inHood(d.slug)).length + c.museums.filter(inHood(d.slug)).length,
|
|
363
|
+
areaType: str(d.areaType), badge: str(d.badge), baseVerdict: str(d.baseVerdict), atmosphere: str(d.atmosphere),
|
|
364
|
+
audiences: Array.isArray(d.audiences) ? (d.audiences as string[]) : [], themes: Array.isArray(d.themes) ? (d.themes as string[]) : [],
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
/** A monument's coordinates, for the anchor landmark. */
|
|
368
|
+
const at = (slug: string) => { const m = c.monuments.find((e) => e.data.slug === slug); return m ? toLatLng(m.data.coordinates as Parameters<typeof toLatLng>[0]) : null; };
|
|
369
|
+
return { hoods, itemsFor, at };
|
|
370
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Public surface of @sarimarcus/content-sites-tourism/neighborhoods (SLA-3444): the neighbourhood content fields,
|
|
2
|
+
// the caps, picks and locator helpers, and the hub and detail page models.
|
|
3
|
+
export * from './neighborhoodCore.ts';
|
|
4
|
+
export {
|
|
5
|
+
neighborhoodDetailModel, neighborhoodHubModel, neighborhoodData, hubOrder, hubFilters, rankItems, resolvePicks, ratingValue, toLatLng, ITEM_ROUTES,
|
|
6
|
+
} from './neighborhoodModel.ts';
|
|
7
|
+
export type {
|
|
8
|
+
NeighborhoodItem, NeighborhoodItems, HoodSummary, LocatorStop, Anchor, ItemType, DetailModelInput, HubModelInput, NeighborhoodCollections, DataOptions, EntryLike,
|
|
9
|
+
} from './neighborhoodModel.ts';
|