url: decideUrl()

in dotcom-rendering/src/model/enhanceCards.ts [44:76]


			url: decideUrl(subLink),
			kickerText:
				!kickerText && supportingContentIsLive ? 'Live' : kickerText,
		};
	});
};

const decideAvatarUrl = (
	tags: TagType[] = [],
	byline?: string,
): string | undefined => {
	const soleContributor = getSoleContributor(tags, byline);
	return soleContributor?.bylineLargeImageUrl ?? undefined;
};

/**
 * This function decides the best URL to link to on a Card or Supporting Content. It will pick the first non-undefined property of the following:
 *
 * `trail.properties.webUrl` - Where CAPI expects the content to be. Fully qualified but turned into a relative URL by DCR if possible. Ignored if the trail is type LinkSnap.
 * `trail.properties.href` - Location that a LinkSnap references.
 * `trail.header.url` - Where Frontend/FAPI expects the content to be. Usually identical to a relative-ized webUrl. In theory this should never get picked but it's the only URL where we're guaranteed it not be undefined which makes TypeScript happy.
 */
const decideUrl = (trail: FESupportingContent | FEFrontCard) => {
	/**
	 * Frontend gives us fully qualified webUrls (https://www.theguardian.com/a/thing) which we want as relative URLs instead
	 *
	 * Don't try to provide a relative URL for LinkSnap, these will link to domains other than www.theguardian.com and therefore wont have a relative path.
	 */
	if (
		!isUndefined(trail.properties.webUrl) &&
		!('type' in trail && trail.type === 'LinkSnap')
	) {
		try {