@@ -10,18 +10,20 @@ import {
1010 palette ,
1111} from '@guardian/source/foundations' ;
1212import { grid } from '../grid' ;
13+ import type { TagType } from '../types/tag' ;
1314
1415type Props = {
15- selected : Selected ;
1616 pageId : string ;
17+ pageTags ?: TagType [ ] ;
1718} ;
1819
1920interface DirectoryPageNavConfig {
2021 pageIds : string [ ] ;
22+ tagIds : string [ ] ;
2123 textColor : string ;
2224 backgroundColor : string ;
23- title : { label : string ; link : string } ;
24- links : { label : string ; href : string ; selectedSlug : string | undefined } [ ] ;
25+ title : { label : string ; id : string } ;
26+ links : { label : string ; id : string } [ ] ;
2527 backgroundImages ?: {
2628 mobile : string ;
2729 mobileLandscape : string ;
@@ -39,32 +41,29 @@ const configs = [
3941 'sport/ng-interactive/2026/feb/04/winter-olympics-results-milano-cortina-2026' ,
4042 'sport/ng-interactive/2026/feb/04/winter-olympics-2026-latest-medal-table-milano-cortina' ,
4143 ] ,
44+ tagIds : [ 'sport/winter-olympics-2026' ] ,
4245 textColor : palette . neutral [ 7 ] ,
4346 backgroundColor : '#CCCCCC' ,
4447 title : {
4548 label : 'Winter Olympics 2026' ,
46- link : 'https://www.theguardian.com/ sport/winter-olympics-2026' ,
49+ id : 'sport/winter-olympics-2026' ,
4750 } ,
4851 links : [
4952 {
5053 label : 'Schedule' ,
51- href : 'https://www.theguardian.com/sport/ng-interactive/2026/feb/04/winter-olympics-full-schedule-milano-cortina-2026' ,
52- selectedSlug : 'schedule' ,
54+ id : 'sport/ng-interactive/2026/feb/04/winter-olympics-full-schedule-milano-cortina-2026' ,
5355 } ,
5456 {
5557 label : 'Results' ,
56- href : 'https://www.theguardian.com/sport/ng-interactive/2026/feb/04/winter-olympics-results-milano-cortina-2026' ,
57- selectedSlug : 'results' ,
58+ id : 'sport/ng-interactive/2026/feb/04/winter-olympics-results-milano-cortina-2026' ,
5859 } ,
5960 {
6061 label : 'Medal table' ,
61- href : 'https://www.theguardian.com/sport/ng-interactive/2026/feb/04/winter-olympics-2026-latest-medal-table-milano-cortina' ,
62- selectedSlug : undefined ,
62+ id : 'sport/ng-interactive/2026/feb/04/winter-olympics-2026-latest-medal-table-milano-cortina' ,
6363 } ,
6464 {
6565 label : 'Full coverage' ,
66- href : 'https://www.theguardian.com/sport/winter-olympics-2026' ,
67- selectedSlug : undefined ,
66+ id : 'sport/winter-olympics-2026' ,
6867 } ,
6968 ] ,
7069 backgroundImages : {
@@ -80,10 +79,6 @@ const configs = [
8079 } ,
8180] satisfies DirectoryPageNavConfig [ ] ;
8281
83- type Configs = typeof configs ;
84- type SelectedSlug = Configs [ number ] [ 'links' ] [ number ] [ 'selectedSlug' ] ;
85- type Selected = Exclude < SelectedSlug , undefined > ;
86-
8782const backgroundImageStyles = (
8883 images ?: DirectoryPageNavConfig [ 'backgroundImages' ] ,
8984) => {
@@ -109,8 +104,14 @@ const backgroundImageStyles = (
109104 } ;
110105} ;
111106
112- export const DirectoryPageNav = ( { selected, pageId } : Props ) => {
113- const config = configs . find ( ( cfg ) => cfg . pageIds . includes ( pageId ) ) ;
107+ export const DirectoryPageNav = ( { pageId, pageTags } : Props ) => {
108+ const config = configs . find (
109+ ( cfg ) =>
110+ cfg . pageIds . includes ( pageId ) ||
111+ cfg . tagIds . some (
112+ ( tagId ) => pageTags ?. some ( ( tag ) => tag . id === tagId ) ,
113+ ) ,
114+ ) ;
114115
115116 if ( ! config ) {
116117 return null ;
@@ -225,24 +226,23 @@ export const DirectoryPageNav = ({ selected, pageId }: Props) => {
225226
226227 return (
227228 < nav css = { nav } >
228- < a href = { config . title . link } css = { largeLinkStyles } >
229+ < a href = { config . title . id } css = { largeLinkStyles } >
229230 { config . title . label }
230231 </ a >
231232 < ul css = { list } >
232233 { config . links . map ( ( link , i ) => (
233- < li key = { link . label } css = { listItem } >
234+ < li
235+ key = { link . label }
236+ css = { listItem }
237+ style = { pageId === link . id ? selectedStyles : { } }
238+ >
234239 < a
235- href = { link . href }
240+ href = { `/ ${ link . id } ` }
236241 css = {
237242 i === config . links . length - 1
238243 ? lastSmallLink
239244 : smallLink
240245 }
241- style = {
242- link . selectedSlug === selected
243- ? selectedStyles
244- : { }
245- }
246246 >
247247 { link . label }
248248 </ a >
0 commit comments