Skip to content

Commit

Permalink
Merge pull request #11965 from ethereum/canonical-trailing-slash
Browse files Browse the repository at this point in the history
fix: remove trailing slash from canonical url
  • Loading branch information
corwintines authored Jan 18, 2024
2 parents 22d6537 + 0ca297f commit 6a16f6e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/PageMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ const PageMetadata: React.FC<IProps> = ({
const path = asPath.replace(/[\?\#].*/, "")
const slug = path.split("/")

/* Set canonical URL w/ language path to avoid duplicate content */
/* e.g. set ethereum.org/about/ to ethereum.org/en/about/ */
const url = new URL(join(locale === DEFAULT_LOCALE ? "" : locale!, path), SITE_URL).href
/**
* Set canonical URL w/ language path to avoid duplicate content
* If English, remove language path
* Remove trailing slash
* @example ethereum.org/about/ -> ethereum.org/about
* @example ethereum.org/pt-br/web3/ -> ethereum.org/pt-br/web3
*/
const url = new URL(join(locale === DEFAULT_LOCALE ? "" : locale!, path), SITE_URL).href.replace(/\/$/, "")
const canonical = canonicalUrl || url

/* Set fallback ogImage based on path */
Expand Down

0 comments on commit 6a16f6e

Please sign in to comment.