Skip to content

Commit

Permalink
Merge branch 'latest' into upgrade-express
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewscfc authored Oct 18, 2024
2 parents 78e1890 + 76b8528 commit 267b5d0
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/app/lib/config/services/somali.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ export const service: DefaultServiceConfig = {
title: 'War',
url: '/somali',
},
{
title: 'Doorashada Mareykanka 2024',
url: '/somali/topics/cv2g4v31x97t',
},
{
title: 'Ganacsi',
url: '/somali/topics/c2dwqd32v4yt',
Expand Down
4 changes: 4 additions & 0 deletions src/app/lib/config/services/urdu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ export const service: DefaultServiceConfig = {
title: 'صفحۂ اول',
url: '/urdu',
},
{
title: 'امریکی صدارتی انتخاب 2024',
url: '/urdu/topics/c0w3wed04e3t',
},
{
title: 'پاکستان',
url: '/urdu/topics/cjgn7n9zzq7t',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,48 +215,55 @@ exports[`AMP Feature Index page Header Navigation link should match text and url
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 2`] = `
{
"text": "امریکی صدارتی انتخاب 2024",
"url": "/urdu/topics/c0w3wed04e3t",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 3`] = `
{
"text": "پاکستان",
"url": "/urdu/topics/cjgn7n9zzq7t",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 3`] = `
exports[`AMP Feature Index page Header Navigation link should match text and url 4`] = `
{
"text": "آس پاس",
"url": "/urdu/topics/cl8l9mveql2t",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 4`] = `
exports[`AMP Feature Index page Header Navigation link should match text and url 5`] = `
{
"text": "ورلڈ",
"url": "/urdu/topics/cw57v2pmll9t",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 5`] = `
exports[`AMP Feature Index page Header Navigation link should match text and url 6`] = `
{
"text": "کھیل",
"url": "/urdu/topics/c340q0p2585t",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 6`] = `
exports[`AMP Feature Index page Header Navigation link should match text and url 7`] = `
{
"text": "فن فنکار",
"url": "/urdu/topics/ckdxnx900n5t",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 7`] = `
exports[`AMP Feature Index page Header Navigation link should match text and url 8`] = `
{
"text": "سائنس",
"url": "/urdu/topics/c40379e2ymxt",
}
`;

exports[`AMP Feature Index page Header Navigation link should match text and url 8`] = `
exports[`AMP Feature Index page Header Navigation link should match text and url 9`] = `
{
"text": "ویڈیو",
"url": "/urdu/topics/c1e0mzr3r2yt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,48 +74,55 @@ exports[`Canonical Feature Index page Header Navigation link should match text a
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 2`] = `
{
"text": "امریکی صدارتی انتخاب 2024",
"url": "/urdu/topics/c0w3wed04e3t",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 3`] = `
{
"text": "پاکستان",
"url": "/urdu/topics/cjgn7n9zzq7t",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 3`] = `
exports[`Canonical Feature Index page Header Navigation link should match text and url 4`] = `
{
"text": "آس پاس",
"url": "/urdu/topics/cl8l9mveql2t",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 4`] = `
exports[`Canonical Feature Index page Header Navigation link should match text and url 5`] = `
{
"text": "ورلڈ",
"url": "/urdu/topics/cw57v2pmll9t",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 5`] = `
exports[`Canonical Feature Index page Header Navigation link should match text and url 6`] = `
{
"text": "کھیل",
"url": "/urdu/topics/c340q0p2585t",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 6`] = `
exports[`Canonical Feature Index page Header Navigation link should match text and url 7`] = `
{
"text": "فن فنکار",
"url": "/urdu/topics/ckdxnx900n5t",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 7`] = `
exports[`Canonical Feature Index page Header Navigation link should match text and url 8`] = `
{
"text": "سائنس",
"url": "/urdu/topics/c40379e2ymxt",
}
`;

exports[`Canonical Feature Index page Header Navigation link should match text and url 8`] = `
exports[`Canonical Feature Index page Header Navigation link should match text and url 9`] = `
{
"text": "ویڈیو",
"url": "/urdu/topics/c1e0mzr3r2yt",
Expand Down
28 changes: 22 additions & 6 deletions src/server/Document/Renderers/litePageTransforms/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ describe('litePageTransforms', () => {
it('should append .lite suffix to valid hrefs', () => {
const html = `
<a href="https://www.bbc.com/news">News</a>
<a href="https://www.bbc.com/serbian/lat">News</a>
<a href="https://www.bbc.com/mundo">News</a>
<a href="https://www.bbcrussian.com/news">News</a>
<a href="/news">News</a>
`;
Expand All @@ -13,31 +15,45 @@ describe('litePageTransforms', () => {

expect(modifiedHtml).toEqual(`
<a href="https://www.bbc.com/news.lite">News</a>
<a href="https://www.bbc.com/serbian/lat.lite">News</a>
<a href="https://www.bbc.com/mundo.lite">News</a>
<a href="https://www.bbcrussian.com/news.lite">News</a>
<a href="/news.lite">News</a>
`);
});

it('should not append .lite suffix to invalid hrefs', () => {
const html = `
const originalHtml = `
<a href="https://www.bbc.co.uk/news">News</a>
<a href="https://www.bbc.com/news.lite">News</a>
<a href="https://www.bbc.com/news.amp">News</a>
<a href="#news">News</a>
<a href="mailto:[email protected]">News</a>
`;

const modifiedHtml = litePageTransforms(html);
const modifiedHtml = litePageTransforms(originalHtml);

expect(modifiedHtml).toEqual(originalHtml);
});

expect(modifiedHtml).toEqual(html);
it('should not append .lite suffix to an invalid "service"', () => {
const originalHtml = `
<a href="https://www.bbc.co.uk/future">Future</a>
<a href="https://www.bbc.com/food">Food</a>
<a href="https://www.bbc.com/weather">Weather</a>
`;

const modifiedHtml = litePageTransforms(originalHtml);

expect(modifiedHtml).toEqual(originalHtml);
});

it('should not append .lite suffix when no anchor tags are present', () => {
const html = '<p>I am a paragraph</p>';
const originalHtml = '<p>I am a paragraph</p>';

const modifiedHtml = litePageTransforms(html);
const modifiedHtml = litePageTransforms(originalHtml);

expect(modifiedHtml).toEqual(html);
expect(modifiedHtml).toEqual(originalHtml);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { Services } from '#app/models/types/global';
import services from '#lib/config/services/loadableConfig';

const SERVICES = Object.keys(services) as Services[];

const VALID_DOMAINS = [
'/',
'localhost',
Expand All @@ -15,9 +20,18 @@ const isValidHref = (href: string) => {
const extension = url?.pathname?.split('.')?.pop() || '';
const startsWithHash = href?.startsWith('#');

const hasReservedRouteExtension =
RESERVED_ROUTE_EXTENSIONS.includes(extension);

const isValidDomain = VALID_DOMAINS.includes(url.hostname);
const isWsService = SERVICES.includes(
url?.pathname?.split('/')?.[1] as Services,
);

return (
VALID_DOMAINS.includes(url.hostname) &&
!RESERVED_ROUTE_EXTENSIONS.includes(extension) &&
isValidDomain &&
isWsService &&
!hasReservedRouteExtension &&
!startsWithHash
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,34 @@ exports[`Canonical Send Header Navigation link should match text and url 1`] = `
`;

exports[`Canonical Send Header Navigation link should match text and url 2`] = `
{
"text": "Doorashada Mareykanka 2024",
"url": "/somali/topics/cv2g4v31x97t",
}
`;

exports[`Canonical Send Header Navigation link should match text and url 3`] = `
{
"text": "Ganacsi",
"url": "/somali/topics/c2dwqd32v4yt",
}
`;

exports[`Canonical Send Header Navigation link should match text and url 3`] = `
exports[`Canonical Send Header Navigation link should match text and url 4`] = `
{
"text": "Cayaaraha",
"url": "/somali/topics/cpzd4zj1pn2t",
}
`;

exports[`Canonical Send Header Navigation link should match text and url 4`] = `
exports[`Canonical Send Header Navigation link should match text and url 5`] = `
{
"text": "Muuqaal",
"url": "/somali/topics/c7pl4k5r9xxt",
}
`;

exports[`Canonical Send Header Navigation link should match text and url 5`] = `
exports[`Canonical Send Header Navigation link should match text and url 6`] = `
{
"text": "Barnaamijyada Idaacadda",
"url": "/somali/topics/cn6rqlrkm0pt",
Expand Down

0 comments on commit 267b5d0

Please sign in to comment.