Every generateStaticParams is gated behind PRERENDER_PLACES and wrapped in the same try/catch the school route uses. The plan claimed authority pages were 'few enough to always prebuild' — but few enough still means the API must be reachable at build time, and in CI it is not: the build failed with ECONNREFUSED rather than degrading to ISR. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015mWQnpye9F299NVRCCSRvj
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
/**
|
|
* Postcode district pages.
|
|
*
|
|
* No phase variants: nobody searches "primary schools in SW11", so the
|
|
* variants would be pages without demand. These exist to catch
|
|
* "schools near <postcode>" and to give London districts a geographic page
|
|
* where the GIAS town field cannot.
|
|
*/
|
|
import { notFound } from 'next/navigation';
|
|
import type { Metadata } from 'next';
|
|
import { fetchPlace, fetchPlaces } from '@/lib/places';
|
|
import { fetchNationalAverages } from '@/lib/api';
|
|
import { PlaceView } from '@/components/places/PlaceView';
|
|
import { absoluteUrl } from '@/lib/site';
|
|
|
|
interface Props { params: Promise<{ outcode: string }> }
|
|
|
|
export const revalidate = 604800;
|
|
export const dynamicParams = true;
|
|
|
|
export async function generateStaticParams(): Promise<Array<{ outcode: string }>> {
|
|
// 1,760 of these; same CI budget argument as the town routes.
|
|
if (process.env.PRERENDER_PLACES !== '1') return [];
|
|
try {
|
|
return (await fetchPlaces())
|
|
.filter((p) => p.kind === 'outcode')
|
|
.map((p) => ({ outcode: p.slug }));
|
|
} catch (error) {
|
|
console.warn('generateStaticParams: API unreachable, falling back to on-demand ISR.', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
const { outcode } = await params;
|
|
const detail = await fetchPlace('outcode', outcode);
|
|
if (!detail) return { title: 'Place Not Found' };
|
|
|
|
const { name, count } = detail.place;
|
|
return {
|
|
title: `Schools near ${name} | schoolcompare`,
|
|
description:
|
|
`${count} schools in the ${name} postcode district, ranked by results, with `
|
|
+ `Ofsted grades and how close you had to live to get a place.`,
|
|
alternates: { canonical: absoluteUrl(`/schools/near/${outcode}`) },
|
|
};
|
|
}
|
|
|
|
export default async function OutcodePage({ params }: Props) {
|
|
const { outcode } = await params;
|
|
const detail = await fetchPlace('outcode', outcode);
|
|
if (!detail) notFound();
|
|
|
|
const national = await fetchNationalAverages().catch(() => null);
|
|
return (
|
|
<PlaceView
|
|
detail={detail}
|
|
englandAverage={national?.primary?.rwm_expected_pct ?? null}
|
|
neighbours={[]}
|
|
/>
|
|
);
|
|
}
|