2026-02-02 20:34:35 +00:00
|
|
|
/**
|
|
|
|
|
* Home Page (SSR)
|
|
|
|
|
* Main landing page with school search and browsing
|
|
|
|
|
*/
|
|
|
|
|
|
2026-08-20 22:10:50 +01:00
|
|
|
import { absoluteUrl } from '@/lib/site';
|
2026-08-14 17:15:09 +01:00
|
|
|
import type { Metadata } from 'next';
|
2026-03-23 21:31:28 +00:00
|
|
|
import { fetchSchools, fetchFilters, fetchDataInfo } from '@/lib/api';
|
2026-08-14 17:15:09 +01:00
|
|
|
import { formatAcademicYear } from '@/lib/utils';
|
2026-02-02 20:34:35 +00:00
|
|
|
import { HomeView } from '@/components/HomeView';
|
2026-06-02 13:46:45 +01:00
|
|
|
import { HowItWorksSection } from '@/components/HowItWorksSection';
|
|
|
|
|
import { EditorialSection } from '@/components/EditorialSection';
|
2026-02-02 20:34:35 +00:00
|
|
|
|
|
|
|
|
interface HomePageProps {
|
2026-02-02 22:09:17 +00:00
|
|
|
searchParams: Promise<{
|
2026-02-02 20:34:35 +00:00
|
|
|
search?: string;
|
|
|
|
|
local_authority?: string;
|
|
|
|
|
school_type?: string;
|
2026-03-28 14:59:40 +00:00
|
|
|
phase?: string;
|
2026-02-02 20:34:35 +00:00
|
|
|
page?: string;
|
|
|
|
|
postcode?: string;
|
|
|
|
|
radius?: string;
|
2026-03-30 10:10:28 +01:00
|
|
|
sort?: string;
|
2026-03-30 10:45:09 +01:00
|
|
|
gender?: string;
|
|
|
|
|
admissions_policy?: string;
|
|
|
|
|
has_sixth_form?: string;
|
2026-02-02 22:09:17 +00:00
|
|
|
}>;
|
2026-02-02 20:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-14 17:15:09 +01:00
|
|
|
/*
|
|
|
|
|
* `title` was the bare string 'Home', which is what the browser tab, the
|
|
|
|
|
* bookmark and the search result all read. `absolute` opts out of the root
|
|
|
|
|
* layout's "%s | schoolcompare" template so the homepage doesn't end up
|
|
|
|
|
* saying the brand twice.
|
|
|
|
|
*/
|
|
|
|
|
export const metadata: Metadata = {
|
2026-08-21 00:21:08 +01:00
|
|
|
/*
|
|
|
|
|
* Intent in the title, differentiator in the description.
|
|
|
|
|
*
|
|
|
|
|
* These queries are owned by the DfE's own "Compare school performance"
|
|
|
|
|
* service, and the old title — brand first, then a near-paraphrase of that
|
|
|
|
|
* service's name — gave a searcher no reason to pick us over it. It drew
|
|
|
|
|
* 0.43% CTR at position 6.1 while the brand query drew 9.16% from the same
|
|
|
|
|
* neighbourhood, so the ranking was never the problem.
|
|
|
|
|
*
|
|
|
|
|
* The title now matches what people type. The description carries the one
|
|
|
|
|
* fact gov.uk does not publish: how close you had to live to get a place.
|
|
|
|
|
*/
|
|
|
|
|
title: { absolute: 'Compare Schools Side by Side | schoolcompare' },
|
|
|
|
|
description:
|
|
|
|
|
'Put five English schools on one screen — SATs, GCSE results, Ofsted grades, and how close you had to live to get a place. Free, no sign-up.',
|
2026-08-20 22:10:50 +01:00
|
|
|
// This page reads eleven search params. They filter a result set; they do
|
|
|
|
|
// not make a new document. Collapsing every combination onto "/" stops the
|
|
|
|
|
// homepage competing with itself for its own head terms.
|
|
|
|
|
alternates: { canonical: absoluteUrl('/') },
|
2026-02-02 20:34:35 +00:00
|
|
|
};
|
|
|
|
|
|
2026-06-02 13:46:45 +01:00
|
|
|
// The page reads searchParams, which makes rendering dynamic by default.
|
|
|
|
|
// We don't use `force-dynamic` here so the internal filter/data-info fetches
|
|
|
|
|
// can still hit Next.js's data cache (configured per-call in lib/api.ts).
|
2026-02-02 20:34:35 +00:00
|
|
|
|
|
|
|
|
export default async function HomePage({ searchParams }: HomePageProps) {
|
2026-02-02 22:09:17 +00:00
|
|
|
// Await search params (Next.js 15 requirement)
|
|
|
|
|
const params = await searchParams;
|
|
|
|
|
|
2026-02-02 20:34:35 +00:00
|
|
|
// Parse search params
|
2026-02-02 22:09:17 +00:00
|
|
|
const page = parseInt(params.page || '1');
|
2026-02-02 22:21:55 +00:00
|
|
|
const radius = params.radius ? parseFloat(params.radius) : undefined;
|
|
|
|
|
|
|
|
|
|
// Check if user has performed a search
|
|
|
|
|
const hasSearchParams = !!(
|
|
|
|
|
params.search ||
|
|
|
|
|
params.local_authority ||
|
|
|
|
|
params.school_type ||
|
2026-03-28 14:59:40 +00:00
|
|
|
params.phase ||
|
2026-03-30 10:45:09 +01:00
|
|
|
params.postcode ||
|
|
|
|
|
params.gender ||
|
|
|
|
|
params.admissions_policy ||
|
|
|
|
|
params.has_sixth_form
|
2026-02-02 22:21:55 +00:00
|
|
|
);
|
2026-02-02 20:34:35 +00:00
|
|
|
|
2026-02-02 21:28:50 +00:00
|
|
|
// Fetch data on server with error handling
|
|
|
|
|
try {
|
2026-03-23 21:31:28 +00:00
|
|
|
const [filtersData, dataInfo] = await Promise.all([fetchFilters(), fetchDataInfo().catch(() => null)]);
|
2026-02-02 22:21:55 +00:00
|
|
|
|
|
|
|
|
// Only fetch schools if there are search parameters
|
|
|
|
|
let schoolsData;
|
|
|
|
|
if (hasSearchParams) {
|
|
|
|
|
schoolsData = await fetchSchools({
|
2026-02-02 22:09:17 +00:00
|
|
|
search: params.search,
|
|
|
|
|
local_authority: params.local_authority,
|
|
|
|
|
school_type: params.school_type,
|
2026-03-28 14:59:40 +00:00
|
|
|
phase: params.phase,
|
2026-02-02 22:09:17 +00:00
|
|
|
postcode: params.postcode,
|
2026-02-02 21:28:50 +00:00
|
|
|
radius,
|
|
|
|
|
page,
|
|
|
|
|
page_size: 50,
|
2026-03-30 10:45:09 +01:00
|
|
|
gender: params.gender,
|
|
|
|
|
admissions_policy: params.admissions_policy,
|
|
|
|
|
has_sixth_form: params.has_sixth_form,
|
2026-02-02 22:21:55 +00:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Empty state by default
|
|
|
|
|
schoolsData = { schools: [], page: 1, page_size: 50, total: 0, total_pages: 0 };
|
|
|
|
|
}
|
2026-02-02 20:34:35 +00:00
|
|
|
|
2026-06-02 13:46:45 +01:00
|
|
|
const resolvedFilters = filtersData || { local_authorities: [], school_types: [], years: [], phases: [], genders: [], admissions_policies: [] };
|
2026-08-14 17:15:09 +01:00
|
|
|
// `unique_schools`, not `total_schools` — the latter is not a field this
|
|
|
|
|
// endpoint returns, and reading it silently yielded null on every request.
|
|
|
|
|
const total = dataInfo?.unique_schools ?? null;
|
|
|
|
|
const years = dataInfo?.years_available ?? [];
|
2026-02-02 21:28:50 +00:00
|
|
|
return (
|
|
|
|
|
<HomeView
|
|
|
|
|
initialSchools={schoolsData}
|
2026-06-02 13:46:45 +01:00
|
|
|
filters={resolvedFilters}
|
|
|
|
|
totalSchools={total}
|
|
|
|
|
howItWorks={hasSearchParams ? null : <HowItWorksSection />}
|
2026-08-14 17:15:09 +01:00
|
|
|
editorial={hasSearchParams ? null : (
|
|
|
|
|
<EditorialSection
|
|
|
|
|
totalSchools={total}
|
|
|
|
|
localAuthorityCount={resolvedFilters.local_authorities.length}
|
|
|
|
|
earliestYearLabel={years.length ? formatAcademicYear(years[0]) : null}
|
|
|
|
|
latestYearLabel={years.length ? formatAcademicYear(years[years.length - 1]) : null}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-02-02 21:28:50 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error fetching data for home page:', error);
|
|
|
|
|
|
2026-06-02 13:46:45 +01:00
|
|
|
const emptyFilters = { local_authorities: [], school_types: [], years: [], phases: [], genders: [], admissions_policies: [] };
|
2026-02-02 21:28:50 +00:00
|
|
|
return (
|
|
|
|
|
<HomeView
|
2026-02-02 21:34:24 +00:00
|
|
|
initialSchools={{ schools: [], page: 1, page_size: 50, total: 0, total_pages: 0 }}
|
2026-06-02 13:46:45 +01:00
|
|
|
filters={emptyFilters}
|
2026-03-23 21:31:28 +00:00
|
|
|
totalSchools={null}
|
2026-06-02 13:46:45 +01:00
|
|
|
howItWorks={hasSearchParams ? null : <HowItWorksSection />}
|
2026-08-14 17:15:09 +01:00
|
|
|
editorial={hasSearchParams ? null : (
|
|
|
|
|
<EditorialSection
|
|
|
|
|
totalSchools={null}
|
|
|
|
|
localAuthorityCount={0}
|
|
|
|
|
earliestYearLabel={null}
|
|
|
|
|
latestYearLabel={null}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-02-02 21:28:50 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-02 20:34:35 +00:00
|
|
|
}
|