Skip to content

Commit

Permalink
fix: issue where canonical was missing trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
tobeycodes committed Jul 24, 2023
1 parent 1494a33 commit cc5fd8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/next/src/components/Yoast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import {
import { useSettings } from '@headstartwp/core/react';
import Head from 'next/head';

function convertUrl(url: string, hostUrl: string, sourceUrl: string) {
return `${hostUrl}${removeSourceUrl({ link: url, backendUrl: sourceUrl })}`;
export function convertUrl(url: string, hostUrl: string, sourceUrl: string) {
return `${hostUrl}${removeSourceUrl({
link: url.replace(/\/?$/, '/'),
backendUrl: sourceUrl,
})}`;
}

type Props = {
Expand Down
15 changes: 15 additions & 0 deletions packages/next/src/components/__tests__/Yoast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { convertUrl } from '../Yoast';

describe('convertUrl', () => {
it('root works without trailing slash', () => {
expect(
convertUrl('https://test.com/test', 'https://test.test.com', 'https://test.com/test'),
).toBe('https://test.test.com/');
});

it('root works with trailing slash', () => {
expect(
convertUrl('https://test.com/test/', 'https://test.test.com', 'https://test.com/test'),
).toBe('https://test.test.com/');
});
});

0 comments on commit cc5fd8e

Please sign in to comment.