From 232f4e688851c6842c9614ae93ac654073a54cdb Mon Sep 17 00:00:00 2001 From: tobey Date: Tue, 1 Aug 2023 05:04:52 -0600 Subject: [PATCH 1/2] fix: issue where canonical was missing trailing slash (#567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NĂ­cholas Oliveira --- .changeset/curly-apricots-stare.md | 5 ++++ packages/next/src/components/Yoast.tsx | 11 ++++++-- .../next/src/components/__tests__/Yoast.tsx | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 .changeset/curly-apricots-stare.md create mode 100644 packages/next/src/components/__tests__/Yoast.tsx diff --git a/.changeset/curly-apricots-stare.md b/.changeset/curly-apricots-stare.md new file mode 100644 index 000000000..1c9c622b5 --- /dev/null +++ b/.changeset/curly-apricots-stare.md @@ -0,0 +1,5 @@ +--- +"@headstartwp/next": patch +--- + +Fix: only convertUrls if url starts with sourceUrl diff --git a/packages/next/src/components/Yoast.tsx b/packages/next/src/components/Yoast.tsx index ce348c3a3..ea6aa258e 100644 --- a/packages/next/src/components/Yoast.tsx +++ b/packages/next/src/components/Yoast.tsx @@ -12,8 +12,15 @@ 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) { + if (!url.startsWith(sourceUrl)) { + return url; + } + + return `${hostUrl}${removeSourceUrl({ + link: url.replace(/\/?$/, '/'), + backendUrl: sourceUrl, + })}`; } type Props = { diff --git a/packages/next/src/components/__tests__/Yoast.tsx b/packages/next/src/components/__tests__/Yoast.tsx new file mode 100644 index 000000000..2405e164e --- /dev/null +++ b/packages/next/src/components/__tests__/Yoast.tsx @@ -0,0 +1,25 @@ +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/'); + }); + + it('external url returns external url', () => { + expect( + convertUrl( + 'https://external.com/test', + 'https://test.test.com', + 'https://test.com/test', + ), + ).toBe('https://external.com/test'); + }); +}); From 62f2fd34e79105a51abf78b1d30f378919484fd9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Aug 2023 11:06:05 +0000 Subject: [PATCH 2/2] chore: version packages (next) --- .changeset/pre.json | 2 ++ packages/core/CHANGELOG.md | 6 ++++++ packages/core/package.json | 2 +- packages/next/CHANGELOG.md | 9 +++++++++ packages/next/package.json | 4 ++-- projects/wp-multisite-i18n-nextjs/package.json | 4 ++-- projects/wp-multisite-nextjs/package.json | 4 ++-- projects/wp-nextjs-ts/package.json | 4 ++-- projects/wp-nextjs/package.json | 4 ++-- 9 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.changeset/pre.json b/.changeset/pre.json index 19bc9736e..a297dfaa8 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -15,8 +15,10 @@ }, "changesets": [ "bright-jokes-learn", + "curly-apricots-stare", "lovely-chicken-sparkle", "mighty-stingrays-pay", + "silent-kiwis-compare", "two-cats-vanish" ] } diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index afbcdec32..ce3a0842b 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,11 @@ # @headstartwp/core +## 1.1.0-next.1 + +### Patch Changes + +- 1494a332: Further Optimize next.js props by removing yoast seo bloat. + ## 1.1.0-next.0 ### Minor Changes diff --git a/packages/core/package.json b/packages/core/package.json index f2f520e62..5d233ef4e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@headstartwp/core", - "version": "1.1.0-next.0", + "version": "1.1.0-next.1", "description": "`@headstartwp/core` is the core package that houses framework-agnostic components and utilities for building headless sites with WordPress.", "homepage": "https://github.com/10up/headstartwp/blob/develop/packages/core/README.md", "license": "MIT", diff --git a/packages/next/CHANGELOG.md b/packages/next/CHANGELOG.md index 4576bed70..d9f449021 100644 --- a/packages/next/CHANGELOG.md +++ b/packages/next/CHANGELOG.md @@ -1,5 +1,14 @@ # @headstartwp/next +## 1.1.0-next.1 + +### Patch Changes + +- 232f4e68: Fix: only convertUrls if url starts with sourceUrl +- 1494a332: Further Optimize next.js props by removing yoast seo bloat. +- Updated dependencies [1494a332] + - @headstartwp/core@1.1.0-next.1 + ## 1.1.0-next.0 ### Minor Changes diff --git a/packages/next/package.json b/packages/next/package.json index d039154c9..36674b01a 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "@headstartwp/next", - "version": "1.1.0-next.0", + "version": "1.1.0-next.1", "description": "`@headstartwp/next` is the Next.js bindings for the headless framework.", "homepage": "https://github.com/10up/headstartwp/blob/develop/packages/next/README.md", "license": "MIT", @@ -48,7 +48,7 @@ "lint": "eslint src" }, "dependencies": { - "@headstartwp/core": "^1.1.0-next.0", + "@headstartwp/core": "^1.1.0-next.1", "modify-source-webpack-plugin": "^4.1.0", "loader-utils": "^3.2.0", "schema-utils": "^4.0.0" diff --git a/projects/wp-multisite-i18n-nextjs/package.json b/projects/wp-multisite-i18n-nextjs/package.json index 9eaa1e39e..2c7ec9809 100644 --- a/projects/wp-multisite-i18n-nextjs/package.json +++ b/projects/wp-multisite-i18n-nextjs/package.json @@ -14,8 +14,8 @@ "lint": "eslint ." }, "dependencies": { - "@headstartwp/core": "^1.1.0-next.0", - "@headstartwp/next": "^1.1.0-next.0", + "@headstartwp/core": "^1.1.0-next.1", + "@headstartwp/next": "^1.1.0-next.1", "@linaria/babel-preset": "^4.4.5", "@linaria/core": "^4.2.10", "@linaria/react": "^4.3.8", diff --git a/projects/wp-multisite-nextjs/package.json b/projects/wp-multisite-nextjs/package.json index 205179fb4..78e5cbf98 100644 --- a/projects/wp-multisite-nextjs/package.json +++ b/projects/wp-multisite-nextjs/package.json @@ -14,8 +14,8 @@ "lint": "eslint ." }, "dependencies": { - "@headstartwp/core": "^1.1.0-next.0", - "@headstartwp/next": "^1.1.0-next.0", + "@headstartwp/core": "^1.1.0-next.1", + "@headstartwp/next": "^1.1.0-next.1", "@linaria/babel-preset": "^4.4.5", "@linaria/core": "^4.2.10", "@linaria/react": "^4.3.8", diff --git a/projects/wp-nextjs-ts/package.json b/projects/wp-nextjs-ts/package.json index 06c011df7..8e7d6a147 100644 --- a/projects/wp-nextjs-ts/package.json +++ b/projects/wp-nextjs-ts/package.json @@ -14,8 +14,8 @@ "lint": "eslint ." }, "dependencies": { - "@headstartwp/core": "^1.1.0-next.0", - "@headstartwp/next": "^1.1.0-next.0", + "@headstartwp/core": "^1.1.0-next.1", + "@headstartwp/next": "^1.1.0-next.1", "@linaria/babel-preset": "^4.4.5", "@linaria/core": "^4.2.10", "@linaria/react": "^4.3.8", diff --git a/projects/wp-nextjs/package.json b/projects/wp-nextjs/package.json index 8ac76ad7e..032662965 100644 --- a/projects/wp-nextjs/package.json +++ b/projects/wp-nextjs/package.json @@ -14,8 +14,8 @@ "lint": "eslint ." }, "dependencies": { - "@headstartwp/core": "^1.1.0-next.0", - "@headstartwp/next": "^1.1.0-next.0", + "@headstartwp/core": "^1.1.0-next.1", + "@headstartwp/next": "^1.1.0-next.1", "@10up/next-redis-cache-provider": "^0.1.5", "@linaria/babel-preset": "^4.4.5", "@linaria/core": "^4.2.10",