From ddefb172f66bcd646dd0b75a7ea8360157dd2ba0 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Thu, 21 Jul 2022 10:45:59 -0700 Subject: Replace/Rename Astro.canonicalURL with new Astro.url helper (#3959) * add Astro.url * Add examples of how to create the canonicalURL Co-authored-by: Matthew Phillips --- examples/docs/src/components/HeadSEO.astro | 4 +++- examples/docs/src/layouts/MainLayout.astro | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'examples/docs/src') diff --git a/examples/docs/src/components/HeadSEO.astro b/examples/docs/src/components/HeadSEO.astro index 5d1a2bcb5..43a19c52b 100644 --- a/examples/docs/src/components/HeadSEO.astro +++ b/examples/docs/src/components/HeadSEO.astro @@ -5,7 +5,9 @@ export interface Props { site: any; canonicalURL: URL | string; } -const { content = {}, canonicalURL } = Astro.props; + +const canonicalURL = new URL(Astro.url.pathname, Astro.site); +const { content = {} } = Astro.props; const formattedContentTitle = content.title ? `${content.title} 🚀 ${SITE.title}` : SITE.title; const imageSrc = content?.image?.src ?? OPEN_GRAPH.image.src; const canonicalImageSrc = new URL(imageSrc, Astro.site); diff --git a/examples/docs/src/layouts/MainLayout.astro b/examples/docs/src/layouts/MainLayout.astro index e9812acdd..93ba323e4 100644 --- a/examples/docs/src/layouts/MainLayout.astro +++ b/examples/docs/src/layouts/MainLayout.astro @@ -9,7 +9,8 @@ import RightSidebar from "../components/RightSidebar/RightSidebar.astro"; import * as CONFIG from "../config"; const { content = {} } = Astro.props; -const currentPage = new URL(Astro.request.url).pathname; +const canonicalURL = new URL(Astro.url.pathname, Astro.site); +const currentPage = Astro.url.pathname; const currentFile = `src/pages${currentPage.replace(/\/$/, "")}.md`; const githubEditUrl = CONFIG.GITHUB_EDIT_URL && CONFIG.GITHUB_EDIT_URL + currentFile; --- @@ -17,7 +18,7 @@ const githubEditUrl = CONFIG.GITHUB_EDIT_URL && CONFIG.GITHUB_EDIT_URL + current - + {content.title ? `${content.title} 🚀 ${CONFIG.SITE.title}` : CONFIG.SITE.title}