diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 6addd2a..8ab262c 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -41,7 +41,7 @@ studymap/ │ └── lib/ # pure TypeScript utilities (no JSX) ├── supabase/ │ └── migrations/ # SQL for the optional, sign-in-gated tables (user_places, -│ # user_home, user_events, competition_saves, +│ # user_home, user_events, saved_places, competition_saves, │ # competition_stats), run once by hand - see SELF-HOSTING.md ├── ARCHITECTURE.md ├── CHANGELOG.md @@ -208,6 +208,7 @@ Pure TypeScript modules. No JSX, no React imports. Each file has a single respon | `competitions-share.ts` | Encodes and decodes competition filters to and from a shareable URL query | | `competition-events.ts` | Flattens a competition's milestones into calendar-friendly events | | `competition-saves.ts` | Save, unsave and count saved competitions (`competition_saves`, `competition_stats` tables) | +| `saved-places.ts` | The visitor's starred places: browser storage, the `?saved=` link, account sync | | `calendar-feed.ts` | Resolves a calendar-feed token to the competitions that user saved, without exposing who they are | | `ics.ts` | Builds RFC 5545 iCalendar text for calendar feeds | | `user-profile.ts` | Onboarding answers (board, field, country, referral source) and their `user_profiles` row | diff --git a/SELF-HOSTING.md b/SELF-HOSTING.md index 18df2c9..a0925fb 100644 --- a/SELF-HOSTING.md +++ b/SELF-HOSTING.md @@ -83,7 +83,9 @@ a Supabase project: 3. In the Supabase SQL editor, run every file in `supabase/migrations/`, in filename order. Each one creates its tables with row-level security already scoped to `auth.uid()`, so users can only ever read or write their own rows. This includes `user_places`, `user_home`, and - `user_events` (the three original sign-in-gated tables), plus `competition_saves` and + `user_events` (the three original sign-in-gated tables), `saved_places` (the stars on public + places, private per user; without it saving still works, kept in the browser only), plus + `competition_saves` and `competition_stats` for the competitions vertical: saves are private per user, and `competition_stats` is a public save-count aggregate kept in sync by a trigger, readable by anyone but writable only by that trigger, never directly. It also includes `user_profiles`, diff --git a/src/app/city/[slug]/page.tsx b/src/app/city/[slug]/page.tsx index ed4fab5..4eff31e 100644 --- a/src/app/city/[slug]/page.tsx +++ b/src/app/city/[slug]/page.tsx @@ -8,6 +8,7 @@ import { findCityPage, placesByType, } from "@/lib/city-pages"; +import { countryOfCity } from "@/lib/country-pages"; import { getPlaces } from "@/lib/places"; import { placeJsonLdScript } from "@/lib/jsonld"; import { humanizeCity, PLACE_TYPE_LABELS } from "@/lib/types"; @@ -48,6 +49,7 @@ export default async function CityPage({ params }: CityPageProps) { const name = humanizeCity(page.city); const grouped = placesByType(page.places); + const country = countryOfCity(getPlaces(), page.city); return ( @@ -60,6 +62,20 @@ export default async function CityPage({ params }: CityPageProps) { dangerouslySetInnerHTML={{ __html: placeJsonLdScript(place) }} /> ))} + {country && ( + + )}

Places in

{name} diff --git a/src/app/country/[code]/opengraph-image.tsx b/src/app/country/[code]/opengraph-image.tsx new file mode 100644 index 0000000..fbdd1a7 --- /dev/null +++ b/src/app/country/[code]/opengraph-image.tsx @@ -0,0 +1,150 @@ +import { ImageResponse } from "next/og"; +import { notFound } from "next/navigation"; + +import { countryPageSlugs, findCountryPage } from "@/lib/country-pages"; +import { loadHeadingFonts } from "@/lib/og-fonts"; +import { getPlaces } from "@/lib/places"; +import { ogCountrySummary } from "@/lib/og"; + +// A different image per country, so shared links stop looking identical (#122, #358). +export const alt = "StudyMap — student places and benefits"; +export const size = { width: 1200, height: 630 }; +export const contentType = "image/png"; + +// The country pages are decided at build time from the dataset; so are their +// images. A slug outside the dataset is a 404, never an edge render. +export const dynamicParams = false; + +export function generateStaticParams(): { code: string }[] { + return countryPageSlugs(getPlaces()); +} + +interface CountryOgImageProps { + params: Promise<{ code: string }>; +} + +export default async function CountryOgImage({ params }: CountryOgImageProps) { + const { code } = await params; + const page = findCountryPage(getPlaces(), code); + if (!page) notFound(); + + const summary = ogCountrySummary(page); + const fonts = (await loadHeadingFonts()).map(({ data, weight }) => ({ + data, + name: "Space Grotesk", + weight, + style: "normal" as const, + })); + const fontFamily = '"Space Grotesk", "Inter", system-ui, sans-serif'; + + return new ImageResponse( +
+ {/* Wordmark: the StudyMap pin mark + name */} +
+
+
+
+ + StudyMap + +
+ + {/* Country name */} +
+ {summary.name} +
+
+ {summary.total} student place{summary.total === 1 ? "" : "s"} in{" "} + {summary.cityCount} {summary.cityCount === 1 ? "city" : "cities"} · crowdsourced +
+ + {/* Category counts */} + {summary.counts.length > 0 && ( +
+ {summary.counts.map((count) => ( +
+ + {count.count} + + {count.label} +
+ ))} + {summary.more > 0 && ( +
+ +{summary.more} more +
+ )} +
+ )} + +
+ studyymap.com +
+
, + { + ...size, + fonts, + }, + ); +} diff --git a/src/app/country/[code]/page.tsx b/src/app/country/[code]/page.tsx new file mode 100644 index 0000000..5be7ab3 --- /dev/null +++ b/src/app/country/[code]/page.tsx @@ -0,0 +1,167 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { notFound } from "next/navigation"; + +import { placesByType } from "@/lib/city-pages"; +import { + countryMetaDescription, + countryPageSlugs, + findCountryPage, + topPlaces, +} from "@/lib/country-pages"; +import { countryJsonLdScript } from "@/lib/jsonld"; +import { getPlaces } from "@/lib/places"; +import { mapStateToSearch } from "@/lib/share"; +import { humanizeCity, PLACE_TYPE_LABELS } from "@/lib/types"; +import type { PlaceType } from "@/lib/types"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { PageContainer } from "@/components/layout/page-container"; + +// Every country page is decided at build time from the dataset; a code that is +// not in it (or not in its one canonical lowercase form) is a 404, never a +// server-rendered miss. +export const dynamicParams = false; + +export function generateStaticParams(): { code: string }[] { + return countryPageSlugs(getPlaces()); +} + +interface CountryPageProps { + params: Promise<{ code: string }>; +} + +export async function generateMetadata({ params }: CountryPageProps): Promise { + const { code } = await params; + const page = findCountryPage(getPlaces(), code); + if (!page) return {}; + return { + title: `${page.name} — student places`, + description: countryMetaDescription(page), + }; +} + +/** A /map link filtered to this country, and to one category when given. */ +function mapHref(country: string, type?: PlaceType): string { + return `/map${mapStateToSearch({ + types: type ? [type] : [], + city: null, + country, + query: "", + placeId: null, + lat: null, + lng: null, + zoom: null, + })}`; +} + +export default async function CountryPage({ params }: CountryPageProps) { + const { code } = await params; + const page = findCountryPage(getPlaces(), code); + if (!page) notFound(); + + const grouped = placesByType(page.places); + const start = topPlaces(page.places); + + return ( + + ", "n")]); + const script = countryJsonLdScript(hostile); + expect(script).not.toContain(""); + expect(script).not.toContain("<"); + expect(JSON.parse(script)["@graph"][1].itemListElement).toHaveLength(1); + }); +}); diff --git a/src/lib/jsonld.ts b/src/lib/jsonld.ts index 732d016..6380fee 100644 --- a/src/lib/jsonld.ts +++ b/src/lib/jsonld.ts @@ -1,4 +1,6 @@ import { site } from "@/lib/site"; +import type { CountryPage } from "@/lib/country-pages"; +import { humanizeCity } from "@/lib/types"; import type { Competition, CompetitionFormat } from "@/lib/types"; import type { Place } from "@/lib/types"; @@ -133,3 +135,42 @@ export function competitionJsonLd(competition: Competition): Record { + const url = `${site.url}/country/${page.slug}`; + return { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "Country", + "@id": `${url}#country`, + name: page.name, + identifier: page.code, + url, + }, + { + "@type": "ItemList", + "@id": `${url}#cities`, + name: `Cities in ${page.name} on StudyMap`, + numberOfItems: page.cities.length, + itemListElement: page.cities.map((entry, index) => ({ + "@type": "ListItem", + position: index + 1, + name: humanizeCity(entry.city), + url: `${site.url}/city/${entry.slug}`, + })), + }, + ], + }; +} + +/** The JSON payload for a country page's `