Skip to content

Commit 9de2409

Browse files
committed
Prefer an appender function to overwriting the media type
1 parent 9c04f7e commit 9de2409

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '../../lib/articleFormat';
1414
import { isMediaCard } from '../../lib/cardHelpers';
1515
import { isWithinTwelveHours, secondsToDuration } from '../../lib/formatTime';
16-
import { replaceLinkNameMedia } from '../../lib/getDataLinkName';
16+
import { appendLinkNameMedia } from '../../lib/getDataLinkName';
1717
import { getZIndex } from '../../lib/getZIndex';
1818
import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount';
1919
import { BETA_CONTAINERS } from '../../model/enhanceCollections';
@@ -569,7 +569,7 @@ export const Card = ({
569569

570570
const resolvedDataLinkName =
571571
media && dataLinkName
572-
? replaceLinkNameMedia(dataLinkName, media.type)
572+
? appendLinkNameMedia(dataLinkName, media.type)
573573
: dataLinkName;
574574

575575
/**

dotcom-rendering/src/lib/decideTrail.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ export const decideTrail = (trail: FETrailType, index = 0): TrailType => {
1616
...trail,
1717
image,
1818
format,
19-
dataLinkName: getDataLinkNameCard(
20-
format,
21-
'0',
22-
index,
23-
image ? 'picture' : 'none',
24-
),
19+
dataLinkName: getDataLinkNameCard(format, '0', index),
2520
};
2621
};

dotcom-rendering/src/lib/getDataLinkName.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,23 @@ export type Group = `${number}` | `${number}+`;
5959
* @see {JSX.IntrinsicAttributes}
6060
*/
6161

62-
type MediaType = CardMediaType | 'none';
63-
6462
export const getDataLinkNameCard = (
6563
format: ArticleFormat,
6664
group: Group,
6765
index: number,
68-
mediaType: MediaType = 'none',
6966
cardStyle?: FEFrontCardStyle,
7067
): string =>
7168
[
7269
getLinkType(format, cardStyle),
7370
`group-${group}`,
7471
`card-@${Math.max(index + 1, 1)}`,
75-
`media-${mediaType}`,
7672
].join(' | ');
7773

78-
export const replaceLinkNameMedia = (
74+
type MediaType = CardMediaType | 'none';
75+
76+
export const appendLinkNameMedia = (
7977
dataLinkName: string,
8078
mediaType: MediaType,
8179
): string => {
82-
return dataLinkName.replace(/media-none/, `media-${mediaType}`);
80+
return `${dataLinkName} | media-${mediaType}`;
8381
};

dotcom-rendering/src/model/enhanceCards.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ export const enhanceCards = (
326326
format,
327327
group,
328328
offset + index,
329-
'none', // we don't know the media type for the card yet, so we set it to none and overwrite at the card level.
330329
faciaCard.card.cardStyle.type,
331330
);
332331

0 commit comments

Comments
 (0)