SPB Git forge

spb/countryatlas

Public
20commits 1branches 0releases
268.3 MBsize
maindefault branch
12 days agolast push
TypeScript 57% Python 38.6% JavaScript 3.6% CSS 0.6%
1.9 KB · 46 lines tsx
Raw Blame History
1import type { Metadata } from 'next';2import { t } from '@/i18n';3import { api, isNotBuilt, safe } from '@/lib/api';4import { routes } from '@/lib/site';5import { toCountryLite, type CountryLite } from '@/lib/types-compare';6import { CompareBuilder } from '@/components/compare/compare-builder';7import { NotBuiltState } from '@/components/data/empty-state';89export const revalidate = 900;1011export const metadata: Metadata = {12  title: t('compare.metaTitle'),13  description: t('compare.description'),14  alternates: { canonical: routes.compare() },15  openGraph: { title: `${t('compare.metaTitle')} — ${t('site.name')}`, description: t('compare.description'), url: routes.compare(), type: 'website' },16};1718/** /compare — the builder: typeahead, ordered chips, presets, "Compare" → /compare/a/b/c. */19export default async function ComparePage({ searchParams }: { searchParams: Promise<Record<string, string | string[] | undefined>> }) {20  const sp = await searchParams;21  let list;22  try {23    list = await api.countries();24  } catch (e) {25    if (isNotBuilt(e)) return <NotBuiltState />;26    throw e;27  }28  const countries: CountryLite[] = list.items.filter((c) => c.kind !== 'aggregate').map(toCountryLite).sort((a, b) => a.name.localeCompare(b.name));29  const similar = await safe(api.countrySimilar('CAN', 'overall', 6));30  const peers = (similar?.peers ?? []).map((p) => toCountryLite(p.country));31  const initial = String(Array.isArray(sp.c) ? sp.c[0] : sp.c ?? '')32    .split(',')33    .map((s) => s.trim().toLowerCase())34    .filter(Boolean);3536  return (37    <>38      <header className="pb-4 pt-6 md:pt-10">39        <h1 className="display text-3xl leading-tight text-ink md:text-5xl">{t('compare.title')}</h1>40        <p className="mt-2 max-w-prose text-sm text-ink-2 md:text-base">{t('compare.sub')}</p>41      </header>42      <CompareBuilder countries={countries} peers={peers} initial={initial} />43    </>44  );45}46