Skip to content

Commit 58aeb6f

Browse files
authored
Merge pull request #13624 from guardian/toc-for-timelines
Add table of contents support to timelines
2 parents f008656 + 29de78c commit 58aeb6f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

dotcom-rendering/src/components/Timeline.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@guardian/source/foundations';
1515
import { ArticleDesign, type ArticleFormat } from '../lib/articleFormat';
1616
import type { NestedArticleElement } from '../lib/renderElement';
17+
import { slugify } from '../model/enhance-H2s';
1718
import { palette } from '../palette';
1819
import type {
1920
DCRSectionedTimelineBlockElement,
@@ -294,7 +295,11 @@ export const Timeline = ({
294295
<>
295296
{timeline.sections.map((section) => (
296297
<section key={section.title}>
297-
<Subheading format={format} topPadding={false}>
298+
<Subheading
299+
format={format}
300+
topPadding={false}
301+
id={slugify(section.title)}
302+
>
298303
{section.title}
299304
</Subheading>
300305
{section.events.map((event) => (

dotcom-rendering/src/model/enhanceTableOfContents.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ export const enhanceTableOfContents = (
8888
title: multiByline.title,
8989
});
9090
}
91+
} else if (
92+
element._type ===
93+
'model.dotcomrendering.pageElements.DCRSectionedTimelineBlockElement'
94+
) {
95+
for (const section of element.sections) {
96+
tocItems.push({
97+
id: slugify(section.title),
98+
title: section.title,
99+
});
100+
}
91101
} else if (
92102
element._type ===
93103
'model.dotcomrendering.pageElements.SubheadingBlockElement' ||

0 commit comments

Comments
 (0)