Skip to content

Commit 34350c4

Browse files
authored
Support league specific pages (#13536)
* select the correct league in the competition selector based on page id * update page title to support competition pages
1 parent 2260d3c commit 34350c4

8 files changed

+45
-13
lines changed

dotcom-rendering/src/components/FootballCompetitionSelect.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const FootballCompetitionSelect = {
2323
args: {
2424
nations: regions,
2525
kind: 'Result',
26+
pageId: 'football/live',
2627
onChange: fn(),
2728
},
2829
play: async ({ args, canvasElement }) => {

dotcom-rendering/src/components/FootballCompetitionSelect.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { palette } from '../palette';
55
type Props = {
66
nations: Regions;
77
kind: FootballMatchKind;
8+
pageId: string;
89
onChange: (competitionTag: string) => void;
910
};
1011

@@ -33,11 +34,13 @@ const getPagePath = (kind: FootballMatchKind) => {
3334
export const FootballCompetitionSelect = ({
3435
nations,
3536
kind,
37+
pageId,
3638
onChange,
3739
}: Props) => (
3840
<Select
3941
label="Choose league:"
4042
onChange={(e) => onChange(e.target.value)}
43+
value={pageId.startsWith('/') ? pageId : `/${pageId}`}
4144
theme={{
4245
textLabel: palette('--football-competition-select-text'),
4346
textUserInput: palette('--football-competition-select-text'),

dotcom-rendering/src/components/FootballMatchesPage.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const Results = {
2020
edition: 'UK',
2121
goToCompetitionSpecificPage: fn(),
2222
renderAds: true,
23+
pageId: 'football/results',
2324
},
2425
} satisfies Story;
2526

dotcom-rendering/src/components/FootballMatchesPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Props = {
2222
goToCompetitionSpecificPage: (tag: string) => void;
2323
getMoreDays?: () => Promise<Result<'failed', FootballMatches>>;
2424
renderAds: boolean;
25+
pageId: string;
2526
};
2627

2728
const createTitle = (kind: FootballMatchKind, edition: EditionId) => {
@@ -48,6 +49,7 @@ export const FootballMatchesPage = ({
4849
goToCompetitionSpecificPage,
4950
getMoreDays,
5051
renderAds,
52+
pageId,
5153
}: Props) => (
5254
<main id="maincontent" data-layout="FootballDataPageLayout">
5355
<div
@@ -95,6 +97,7 @@ export const FootballMatchesPage = ({
9597
<FootballCompetitionSelect
9698
nations={nations}
9799
kind={kind}
100+
pageId={pageId}
98101
onChange={goToCompetitionSpecificPage}
99102
/>
100103
</div>

dotcom-rendering/src/components/FootballMatchesPageWrapper.importable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FootballMatchesPage } from './FootballMatchesPage';
88

99
const goToCompetitionSpecificPage =
1010
(guardianBaseUrl: string) => (path: string) => {
11-
const url = `${guardianBaseUrl}/${path}`;
11+
const url = `${guardianBaseUrl}${path}`;
1212
window.location.assign(url);
1313
};
1414

@@ -19,6 +19,7 @@ type Props = {
1919
initialDays: FootballMatches;
2020
edition: EditionId;
2121
renderAds: boolean;
22+
pageId: string;
2223
};
2324

2425
export const FootballMatchesPageWrapper = ({
@@ -28,6 +29,7 @@ export const FootballMatchesPageWrapper = ({
2829
initialDays,
2930
edition,
3031
renderAds,
32+
pageId,
3133
}: Props) => (
3234
<FootballMatchesPage
3335
regions={nations}
@@ -39,5 +41,6 @@ export const FootballMatchesPageWrapper = ({
3941
guardianBaseUrl,
4042
)}
4143
renderAds={renderAds}
44+
pageId={pageId}
4245
/>
4346
);

dotcom-rendering/src/layouts/FootballDataPageLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const FootballDataPageLayout = ({ footballData }: Props) => {
6868
initialDays={footballData.matchesList}
6969
edition={footballData.editionId}
7070
renderAds={renderAds}
71+
pageId={footballData.config.pageId}
7172
/>
7273
</Island>
7374

dotcom-rendering/src/server/handler.footballDataPage.web.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ import { makePrefetchHeader } from './lib/header';
1717
import { recordTypeAndPlatform } from './lib/logging-store';
1818
import { renderFootballDataPage } from './render.footballDataPage.web';
1919

20-
const decidePageKind = (
21-
canonicalUrl: string | undefined,
22-
): FootballMatchKind => {
23-
if (canonicalUrl?.includes('live')) {
20+
const decidePageKind = (pageId: string): FootballMatchKind => {
21+
if (pageId?.includes('live')) {
2422
return 'Live';
2523
}
2624

27-
if (canonicalUrl?.includes('results')) {
25+
if (pageId?.includes('results')) {
2826
return 'Result';
2927
}
3028

31-
if (canonicalUrl?.includes('fixtures')) {
29+
if (pageId?.includes('fixtures')) {
3230
return 'Fixture';
3331
}
3432

@@ -71,7 +69,7 @@ const parseFEFootballData = (data: FEFootballDataPage): DCRFootballDataPage => {
7169

7270
return {
7371
matchesList: parsedMatchesList.value,
74-
kind: decidePageKind(data.canonicalUrl),
72+
kind: decidePageKind(data.config.pageId),
7573
nextPage: data.nextPage,
7674
previousPage: data.previousPage,
7775
regions: parseFEFootballCompetitionRegions(data.filters),

dotcom-rendering/src/server/render.footballDataPage.web.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FootballDataPage } from '../components/FootballDataPage';
44
import type {
55
DCRFootballDataPage,
66
FootballMatchKind,
7+
Regions,
78
} from '../footballMatches';
89
import {
910
ASSET_ORIGIN,
@@ -31,14 +32,31 @@ const decideDescription = (kind: FootballMatchKind) => {
3132
}
3233
};
3334

34-
const decideTitle = (kind: FootballMatchKind) => {
35+
const decideTitle = (
36+
kind: FootballMatchKind,
37+
pageId: string,
38+
regions: Regions,
39+
) => {
40+
const pagePath = pageId.startsWith('/') ? pageId.slice(1) : pageId;
41+
const competitionName = regions
42+
.flatMap((region) => region.competitions) // Flatten all competitions into a single array
43+
.find((competition) => competition.url === `/${pagePath}`)?.name;
44+
45+
const footballTitle = '| Football | The Guardian';
46+
3547
switch (kind) {
3648
case 'Live':
37-
return 'Live matches | Football | The Guardian';
49+
return `${
50+
competitionName ? `Today's ${competitionName} ` : 'Live '
51+
}matches ${footballTitle}`;
3852
case 'Result':
39-
return 'All results | Football | The Guardian';
53+
return `${
54+
competitionName ? `${competitionName} ` : 'All '
55+
}results ${footballTitle}`;
4056
case 'Fixture':
41-
return 'All fixtures | Football | The Guardian';
57+
return `${
58+
competitionName ? `${competitionName} ` : 'All '
59+
}fixtures ${footballTitle}`;
4260
}
4361
};
4462

@@ -90,7 +108,11 @@ export const renderFootballDataPage = (footballData: DCRFootballDataPage) => {
90108
scriptTags,
91109
css: extractedCss,
92110
html,
93-
title: decideTitle(footballData.kind),
111+
title: decideTitle(
112+
footballData.kind,
113+
footballData.config.pageId,
114+
footballData.regions,
115+
),
94116
description: decideDescription(footballData.kind),
95117
canonicalUrl: footballData.canonicalUrl,
96118
guardian: createGuardian({

0 commit comments

Comments
 (0)