Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 |
Expand Down
4 changes: 3 additions & 1 deletion SELF-HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
16 changes: 16 additions & 0 deletions src/app/city/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (
<PageContainer>
Expand All @@ -60,6 +62,20 @@ export default async function CityPage({ params }: CityPageProps) {
dangerouslySetInnerHTML={{ __html: placeJsonLdScript(place) }}
/>
))}
{country && (
<nav aria-label="Breadcrumb" className="mb-2 text-sm text-muted-foreground">
<Link
href={`/country/${country.slug}`}
className="underline-offset-4 hover:text-foreground hover:underline"
>
{country.name}
</Link>
<span aria-hidden className="mx-1.5">
/
</span>
<span aria-current="page">{name}</span>
</nav>
)}
<p className="kicker">Places in</p>
<h1 className="mt-3 font-heading text-3xl font-bold tracking-tight sm:text-4xl">
{name}
Expand Down
150 changes: 150 additions & 0 deletions src/app/country/[code]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -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(
<div
style={{
width: 1200,
height: 630,
background: "#0A0A0A",
color: "#FAFAFA",
display: "flex",
flexDirection: "column",
padding: "64px 76px",
fontFamily,
}}
>
{/* Wordmark: the StudyMap pin mark + name */}
<div style={{ display: "flex", alignItems: "center", gap: 14 }}>
<div
style={{
width: 34,
height: 34,
borderRadius: "50% 50% 50% 0",
transform: "rotate(-45deg)",
background: "#F59E0B",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<div
style={{ width: 12, height: 12, borderRadius: 999, background: "#0A0A0A" }}
/>
</div>
<span style={{ fontSize: 32, fontWeight: 700, letterSpacing: "-0.02em" }}>
StudyMap
</span>
</div>

{/* Country name */}
<div
style={{
marginTop: 104,
fontSize: 96,
fontWeight: 700,
letterSpacing: "-0.02em",
lineHeight: 1.02,
}}
>
{summary.name}
</div>
<div
style={{
display: "flex",
marginTop: 18,
fontSize: 28,
color: "#A1A1AA",
}}
>
{summary.total} student place{summary.total === 1 ? "" : "s"} in{" "}
{summary.cityCount} {summary.cityCount === 1 ? "city" : "cities"} · crowdsourced
</div>

{/* Category counts */}
{summary.counts.length > 0 && (
<div style={{ display: "flex", gap: 14, marginTop: 52, flexWrap: "wrap" }}>
{summary.counts.map((count) => (
<div
key={count.label}
style={{
display: "flex",
alignItems: "center",
gap: 12,
background: "#18181B",
border: "1px solid #27272A",
borderRadius: 999,
padding: "14px 26px",
}}
>
<span style={{ fontSize: 28, fontWeight: 700, color: "#F59E0B" }}>
{count.count}
</span>
<span style={{ fontSize: 24, color: "#D4D4D8" }}>{count.label}</span>
</div>
))}
{summary.more > 0 && (
<div
style={{
display: "flex",
alignItems: "center",
background: "transparent",
border: "1px solid #27272A",
borderRadius: 999,
padding: "14px 26px",
fontSize: 24,
color: "#71717A",
}}
>
+{summary.more} more
</div>
)}
</div>
)}

<div style={{ marginTop: "auto", fontSize: 20, color: "#71717A" }}>
studyymap.com
</div>
</div>,
{
...size,
fonts,
},
);
}
167 changes: 167 additions & 0 deletions src/app/country/[code]/page.tsx
Original file line number Diff line number Diff line change
@@ -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<Metadata> {
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 (
<PageContainer>
<script
type="application/ld+json"
// A Country with an ItemList of its cities; real names and counts only.
dangerouslySetInnerHTML={{ __html: countryJsonLdScript(page) }}
/>
<p className="kicker">Places in</p>
<h1 className="mt-3 font-heading text-3xl font-bold tracking-tight sm:text-4xl">
{page.name}
</h1>
<p className="mt-2 max-w-2xl text-muted-foreground">
{page.places.length} place{page.places.length === 1 ? "" : "s"} across{" "}
{page.cities.length} {page.cities.length === 1 ? "city" : "cities"} in {page.name}
, from the crowdsourced StudyMap dataset.
</p>

<Card className="mt-6">
<CardHeader>
<CardTitle>By category</CardTitle>
</CardHeader>
<CardContent>
<ul className="flex flex-wrap gap-2">
{grouped.map(([type, places]) => (
<li key={type}>
<Link
href={mapHref(page.code, type)}
className="inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-sm hover:bg-muted"
>
<span className="font-semibold tabular-nums">{places.length}</span>
{PLACE_TYPE_LABELS[type]}
</Link>
</li>
))}
</ul>
</CardContent>
</Card>

<section className="mt-8" aria-labelledby="country-cities">
<h2
id="country-cities"
className="font-heading text-lg font-semibold tracking-tight"
>
Cities
<span className="ml-2 text-sm font-normal text-muted-foreground">
{page.cities.length}
</span>
</h2>
<ul className="mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
{page.cities.map((entry) => (
<li key={entry.slug}>
<Link
href={`/city/${entry.slug}`}
className="flex items-center justify-between rounded-md border px-3 py-2 text-sm hover:bg-muted"
>
<span className="font-medium">{humanizeCity(entry.city)}</span>
<span className="tabular-nums text-muted-foreground">{entry.count}</span>
</Link>
</li>
))}
</ul>
</section>

<section className="mt-8" aria-labelledby="country-start">
<h2
id="country-start"
className="font-heading text-lg font-semibold tracking-tight"
>
Start here
</h2>
<ul className="mt-3 grid gap-3 sm:grid-cols-2">
{start.map((place) => (
<li key={place.id}>
<Card size="sm" className="h-full">
<CardHeader>
<CardTitle>{place.name}</CardTitle>
</CardHeader>
<CardContent className="flex flex-wrap items-center gap-2">
<span className="text-muted-foreground">
{PLACE_TYPE_LABELS[place.type]} · {humanizeCity(place.city)}
</span>
<Link
href={`/map?place=${encodeURIComponent(place.id)}`}
className="text-sm font-medium text-primary underline-offset-4 hover:underline"
>
Open on map
</Link>
</CardContent>
</Card>
</li>
))}
</ul>
</section>

<div className="mt-10">
<Button asChild variant="outline">
<Link href={mapHref(page.code)}>Explore {page.name} on the map</Link>
</Button>
</div>
</PageContainer>
);
}
6 changes: 6 additions & 0 deletions src/app/docs/(article)/privacy-data/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const TABLES: { name: string; stores: string; note?: string }[] = [
name: "user_events",
stores: "Personal calendar events you've added on top of the public exam calendar.",
},
{
name: "saved_places",
stores:
"Which public places you've starred on the map - just a list of ids, nothing else.",
note: "Also kept in this browser, so it works without an account; signing in merges the two.",
},
{
name: "competition_saves",
stores: "Which competitions you've saved - just a list of ids, nothing else.",
Expand Down
Loading
Loading