From b97f4d520d39dbf95cd9c145b029fe439bc5b906 Mon Sep 17 00:00:00 2001 From: ridhozhr10 Date: Sat, 1 Jun 2024 08:00:24 +0700 Subject: [PATCH] fix: opengraph stuff --- src/app/posts/[...path]/page.tsx | 12 ++++++++++-- src/app/tags/[tag]/page.tsx | 8 ++++++++ src/constants.ts | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app/posts/[...path]/page.tsx b/src/app/posts/[...path]/page.tsx index 7f8ee2a..c294862 100644 --- a/src/app/posts/[...path]/page.tsx +++ b/src/app/posts/[...path]/page.tsx @@ -91,6 +91,14 @@ export function generateMetadata({ params }: Props): Metadata { } return { title: `${params.path.join("/")} Posts :: Ridho Azhar`, + metadataBase: new URL(baseURL), + robots: { follow: true, index: true }, + openGraph: { + url: `/posts/${params.path.join("/")}`, + title: `${params.path.join("/")} Posts :: Ridho Azhar`, + images: `/img/smug-ico.png`, + type: "website", + }, }; } @@ -100,7 +108,7 @@ export function generateMetadata({ params }: Props): Metadata { const post = data.post; const title = `${post.title} :: Ridho Azhar`; return { - metadataBase: new URL(`${baseURL}/posts/${post.path.join("/")}`), + metadataBase: new URL(baseURL), title, description: post.description, robots: { follow: true, index: true }, @@ -108,7 +116,7 @@ export function generateMetadata({ params }: Props): Metadata { title, url: `${baseURL}/posts/${post.path.join("/")}`, description: post.description, - images: [`${baseURL}${post.ogImage.url}`], + images: [post.ogImage.url], type: "article", authors: "ridhozhr10.github.io", publishedTime: post.created_at, diff --git a/src/app/tags/[tag]/page.tsx b/src/app/tags/[tag]/page.tsx index 7f191b1..22b62ad 100644 --- a/src/app/tags/[tag]/page.tsx +++ b/src/app/tags/[tag]/page.tsx @@ -5,6 +5,7 @@ import dayjs from "dayjs"; import "@/app/posts/style.scss"; import { Metadata } from "next"; import { BiTagAlt } from "react-icons/bi"; +import { baseURL } from "@/constants"; type Props = { params: { @@ -59,8 +60,15 @@ export function generateMetadata({ params }: Props): Metadata { const title = `#${params.tag} :: Ridho Azhar`; return { + metadataBase: new URL(baseURL), title, robots: { follow: true, index: true }, + openGraph: { + title: `title`, + url: `/tags/${params.tag}`, + images: `/img/smug-ico.png`, + type: "website", + }, }; } export function generateStaticParams() { diff --git a/src/constants.ts b/src/constants.ts index fa6205e..b3f1384 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -11,14 +11,14 @@ self proclaimed friendly person (trust me), black coffee enjoyer`; export const baseMetadata = (path: string, titlePrefix?: string): Metadata => { return { - metadataBase: new URL(`${baseURL}${path ? "/" : ""}${path}`), + metadataBase: new URL(`${baseURL}`), title: `${titlePrefix || ""}${titlePrefix ? " :: " : ""}${title}`, description, openGraph: { title: `${titlePrefix || ""}${titlePrefix ? " :: " : ""}${title}`, - url: `${baseURL}${path ? "/" : ""}${path}`, + url: `${path ? "/" : ""}${path}`, description: description, - images: `${baseURL}/img/smug-ico.png`, + images: `/img/smug-ico.png`, type: "website", }, };