jonasmerlin / astro-seo

Makes it easy to add information that is relevant for SEO to your Astro app.
MIT License
908 stars 50 forks source link

Make some properties that can sometimes use the URL constructor accept the URL type #70

Closed cpeaustriajc closed 1 year ago

cpeaustriajc commented 1 year ago

The component throws an error when I pass a URL type as an argument, this fixes that error so that when creating a URL for social images.

Example:

---
import { SEO } from "astro-seo";
import aboutImage from "~/assets/images/image.jpg";

const openGraphImage = await getImage({ src: aboutImage, format: "jpeg" });
const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
const socialImageUrl = new URL(openGraphImage.src, Astro.url)
---

<html>
  <head>
    <SEO
      openGraph={{
        // Throws an error because it only accepts string
        image: socialImageUrl,
        url: canonicalUrl
      }}    
    />
  </head>
  <body>
    <!-- Body Content -->
  </body>
</html
jonasmerlin commented 1 year ago

@jaycedotbin Thank you for this contribution! I added a test and merged it and it will land with the next version.

jonasmerlin commented 1 year ago

This has been released as part of v0.7.5