diff --git a/.changeset/unlucky-panthers-yawn.md b/.changeset/unlucky-panthers-yawn.md new file mode 100644 index 000000000000..b8e325b15990 --- /dev/null +++ b/.changeset/unlucky-panthers-yawn.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Deprecate Astro.canonicalURL, in favor of Astro.url instead. diff --git a/.changeset/yellow-drinks-judge.md b/.changeset/yellow-drinks-judge.md new file mode 100644 index 000000000000..fdd65d6b93a2 --- /dev/null +++ b/.changeset/yellow-drinks-judge.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Add Astro.url helper for getting the request URL diff --git a/examples/blog-multiple-authors/astro.config.mjs b/examples/blog-multiple-authors/astro.config.mjs index 5a51e487a713..2b6a0fe14062 100644 --- a/examples/blog-multiple-authors/astro.config.mjs +++ b/examples/blog-multiple-authors/astro.config.mjs @@ -5,4 +5,5 @@ import preact from '@astrojs/preact'; export default defineConfig({ // Enable the Preact integration to support Preact JSX components. integrations: [preact()], + site: `http://astro.build` }); diff --git a/examples/blog-multiple-authors/src/layouts/post.astro b/examples/blog-multiple-authors/src/layouts/post.astro index b940bbb4075b..8aaa5ba5e16e 100644 --- a/examples/blog-multiple-authors/src/layouts/post.astro +++ b/examples/blog-multiple-authors/src/layouts/post.astro @@ -1,10 +1,9 @@ --- import MainHead from "../components/MainHead.astro"; import Nav from "../components/Nav.astro"; -import authorData from "../data/authors.json"; const { content } = Astro.props; -let canonicalURL = Astro.canonicalURL; +const canonicalURL = new URL(Astro.url.pathname, Astro.site); --- diff --git a/examples/blog-multiple-authors/src/pages/about.astro b/examples/blog-multiple-authors/src/pages/about.astro index 2d2c9665baa9..0edb1446e67e 100644 --- a/examples/blog-multiple-authors/src/pages/about.astro +++ b/examples/blog-multiple-authors/src/pages/about.astro @@ -4,7 +4,7 @@ import Nav from "../components/Nav.astro"; let title = "About"; let description = "About page of an example blog on Astro"; -let canonicalURL = Astro.canonicalURL; +const canonicalURL = new URL(Astro.url.pathname, Astro.site); --- diff --git a/examples/blog-multiple-authors/src/pages/authors/[author].astro b/examples/blog-multiple-authors/src/pages/authors/[author].astro index cc83c6bbb29b..368fdd5919f2 100644 --- a/examples/blog-multiple-authors/src/pages/authors/[author].astro +++ b/examples/blog-multiple-authors/src/pages/authors/[author].astro @@ -13,6 +13,7 @@ export async function getStaticPaths() { const { allPosts } = Astro.props; const title = "Don’s Blog"; const description = "An example blog on Astro"; +const canonicalURL = new URL(Astro.url.pathname, Astro.site); /** filter posts by author, sort by date */ const posts = allPosts @@ -28,7 +29,7 @@ const author = authorData[posts[0].frontmatter.author]; {title} {description} image={posts[0].frontmatter.image} - canonicalURL={Astro.canonicalURL.toString()} + canonicalURL={canonicalURL.toString()} />