Skip to content

Commit

Permalink
WSTEAM1-1367: Remove .amp extension on alternate links for amp pages …
Browse files Browse the repository at this point in the history
…only.- (#12091)

* WSTEAM1-1367: Update

* WSTEAM1-1367: update
  • Loading branch information
shayneahchoon authored Oct 24, 2024
1 parent abef9c6 commit 39b1870
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
41 changes: 41 additions & 0 deletions src/app/components/Metadata/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,47 @@ it(`should render the canonical link's top level domain as .co.uk for UK article
});
});

it(`should render canonical alternative links for UK article AMP pages`, async () => {
render(
<MetadataWithContext
service="sport"
platform="amp"
bbcOrigin={dotCoDotUKOrigin}
id="c0000000001o"
pageType={ARTICLE_PAGE}
pathname="/sport/cricket/articles/c0000000001o"
isUK
{...newsArticleMetadataProps}
/>,
);

const expected = [
{
href: `https://www.bbc.com/sport/cricket/articles/c0000000001o`,
hreflang: 'x-default',
},
{
href: `https://www.bbc.com/sport/cricket/articles/c0000000001o`,
hreflang: 'en',
},
{
href: `https://www.bbc.co.uk/sport/cricket/articles/c0000000001o`,
hreflang: 'en-gb',
},
];

await waitFor(() => {
const actual = Array.from(
document.querySelectorAll('head > link[rel="alternate"]'),
).map(tag => ({
href: tag.getAttribute('href'),
hreflang: tag.getAttribute('hreflang'),
}));

expect(actual).toEqual(expected);
});
});

it(`should render the canonical link's top level domain as .com for WS article pages`, async () => {
render(
<MetadataWithContext
Expand Down
33 changes: 18 additions & 15 deletions src/app/components/Metadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,30 @@ const MetadataContainer = ({
} = useTheme();
const appleTouchIcon = getAppleTouchUrl(service);
const isEnglishService = ENGLISH_SERVICES.includes(service);
const pathsForUkLink = [
'/sport/formula1',
'/sport/cricket/articles',
'/sport/rugby_union/articles',
'/sport/rugby_league/articles',
];

const isUKLink = pathsForUkLink.some(
path => pathname && pathname.startsWith(path),
);

const showAlternateUKAmp = !isUKLink && isAmp;

const alternateLinksEnglishSites = [
{
href: isAmp ? ampNonUkLink : canonicalNonUkLink,
href: showAlternateUKAmp ? ampNonUkLink : canonicalNonUkLink,
hrefLang: 'x-default',
},
{
href: isAmp ? ampNonUkLink : canonicalNonUkLink,
href: showAlternateUKAmp ? ampNonUkLink : canonicalNonUkLink,
hrefLang: 'en',
},
{
href: isAmp ? ampUkLink : canonicalUkLink,
href: showAlternateUKAmp ? ampUkLink : canonicalUkLink,
hrefLang: 'en-gb',
},
];
Expand All @@ -103,18 +116,8 @@ const MetadataContainer = ({
},
];

const pathsForUkLink = [
'/sport/formula1',
'/sport/cricket/articles',
'/sport/rugby_union/articles',
'/sport/rugby_league/articles',
];

const isSport = pathsForUkLink.some(
path => pathname && pathname.startsWith(path),
);

const canonicalToUse = isUK && isSport ? canonicalUkLink : canonicalNonUkLink;
const canonicalToUse =
isUK && isUKLink ? canonicalUkLink : canonicalNonUkLink;

const htmlAttributes = {
dir,
Expand Down

0 comments on commit 39b1870

Please sign in to comment.