fix og:image

This commit is contained in:
Surjith S M
2022-11-11 14:32:59 +05:30
parent 32e72f2bfb
commit 26cfb7fdcc
2 changed files with 16 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { defineConfig } from 'astro/config'; import { defineConfig } from "astro/config";
// https://astro.build/config // https://astro.build/config
import tailwind from "@astrojs/tailwind"; import tailwind from "@astrojs/tailwind";
@@ -14,5 +14,6 @@ import mdx from "@astrojs/mdx";
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [tailwind(), alpinejs(), image(), mdx()] site: "https://astroship.web3templates.com",
integrations: [tailwind(), alpinejs(), image(), mdx()],
}); });

View File

@@ -3,10 +3,12 @@ import { SEO } from "astro-seo";
import Footer from "@components/footer.astro"; import Footer from "@components/footer.astro";
import Navbar from "@components/navbar/navbar.astro"; import Navbar from "@components/navbar/navbar.astro";
import "@fontsource/inter/variable.css"; import "@fontsource/inter/variable.css";
import { log } from "astro/dist/core/logger/core";
export interface Props { export interface Props {
title: string; title: string;
} }
// const { src } = await getImage({ // const { src } = await getImage({
// src: "../../assets/hero.png", // src: "../../assets/hero.png",
// width: 800, // width: 800,
@@ -14,9 +16,15 @@ export interface Props {
// format: "avif", // format: "avif",
// }); // });
// console.log(src); // console.log(src);
const resolvedImageWithDomain = new URL("/opengraph.jpg", Astro.url).toString();
const canonicalURL = new URL(Astro.url.pathname, Astro.site).toString();
const resolvedImageWithDomain = new URL(
"/opengraph.jpg",
Astro.site
).toString();
const { title } = Astro.props; const { title } = Astro.props;
console.log(resolvedImageWithDomain, Astro.url);
const makeTitle = title const makeTitle = title
? title + " | " + "Astroship" ? title + " | " + "Astroship"
@@ -35,6 +43,7 @@ const makeTitle = title
<SEO <SEO
title={makeTitle} title={makeTitle}
description="Astroship is a starter website template for Astro built with TailwindCSS." description="Astroship is a starter website template for Astro built with TailwindCSS."
canonical={canonicalURL}
twitter={{ twitter={{
creator: "@surjithctly", creator: "@surjithctly",
site: "@web3templates", site: "@web3templates",
@@ -42,6 +51,7 @@ const makeTitle = title
}} }}
openGraph={{ openGraph={{
basic: { basic: {
url: canonicalURL,
type: "website", type: "website",
title: `Astroship - Starter Template for Astro`, title: `Astroship - Starter Template for Astro`,
image: resolvedImageWithDomain, image: resolvedImageWithDomain,