Skip to content

Commit 3e6e7d2

Browse files
committed
Added More OG Images + Tweaked Existing ones
1 parent 710b986 commit 3e6e7d2

7 files changed

Lines changed: 38 additions & 15 deletions

File tree

‎public/backgrounds/og-bg.jpg‎

223 KB
Loading

‎public/og.png‎

633 KB
Loading

‎src/app/api/og/route.tsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @next/next/no-img-element */
2-
import { getValueFromKey } from "@/lib/helpers/seo"
2+
import { absoluteURL, getValueFromKey } from "@/lib/helpers/seo"
33
import { formatDate } from "date-fns"
44
import { ImageResponse } from "next/og"
55

@@ -16,9 +16,17 @@ export async function GET(req: Request) {
1616
const title = getValueFromKey(searchParams,"title","ArsenTech Blog")
1717
const description = getValueFromKey(searchParams,"description","Learn about cybersecurity, tech tutorials, unique coding projects, and other tech-related posts all in one place.")
1818
const date = new Date(getValueFromKey(searchParams,"date",new Date().toDateString()))
19-
19+
const bgType = getValueFromKey(searchParams,"bg","gradient") as "image" | "gradient";
20+
const bgImage: React.CSSProperties = bgType==="image" ? {
21+
backgroundImage: `url(${absoluteURL("/backgrounds/og-bg.jpg")})`,
22+
backgroundRepeat: "no-repeat",
23+
backgroundPosition: "center",
24+
backgroundSize: "contain"
25+
} : {
26+
backgroundImage: "linear-gradient(140deg,#22b455 25%,#1dd1a1)",
27+
}
2028
return new ImageResponse((
21-
<div style={{backgroundImage: "linear-gradient(140deg,#22b455 25%,#1dd1a1)"}} tw="flex flex-col w-full h-full items-center justify-between p-5 text-white">
29+
<div style={bgImage} tw="flex flex-col w-full h-full items-center justify-between p-5 text-white">
2230
<img src={`${siteUrl}/arsentech-dark.svg`} alt="ArsenTech" tw="mb-3" width={300} height={64}/>
2331
<div tw="flex items-center justify-center flex-col">
2432
<h1 tw="text-[70px] my-0 font-semibold">{title}</h1>

‎src/app/categories/[category]/page.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ export const generateMetadata = async({params, searchParams}: PageProps): Promis
2727
const currentPage = page ? parseInt(page) : 1;
2828
const postsPerPage = pageSize ? parseInt(pageSize) : POSTS_IN_SEARCH;
2929
const totalPages = Math.ceil(results.length / postsPerPage)
30-
const now = new Date()
31-
32-
const meta = {
30+
const now = new Date(), meta = {
3331
title: `Top ${results.length} "${categoryDecoded}" blog posts - Updated ${now.getFullYear()}`,
3432
description: `Explore {results.length} posts from the "${categoryDecoded}" category — from coding tutorials to tech insights`,
3533
}
36-
3734
const ogImage = absoluteURL(`/api/og?title=${encodeURIComponent(meta.title)}&description=${encodeURIComponent(meta.description)}&date=${now.toISOString()}`)
38-
3935
return {
4036
title: meta.title,
4137
description: meta.description,

‎src/app/layout.tsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,30 @@ export const metadata: Metadata = {
3737
},
3838
alternates: {
3939
canonical: absoluteURL("/")
40-
}
40+
},
41+
openGraph: {
42+
title: "ArsenTech's Official Blog Website",
43+
description: "Your go-to hub for tech tutorials, antivirus comparisons, and in-depth guides for programmers, tech enthusiasts, and more tech related curious minds.",
44+
url: absoluteURL("/"),
45+
siteName: "ArsenTech Blog",
46+
locale: "en_US",
47+
type: "website",
48+
images: {
49+
url: "/og.png",
50+
width: 1200,
51+
height: 630
52+
}
53+
},
54+
twitter: {
55+
images: [{
56+
url: "/og.png",
57+
width: 1200,
58+
height: 630
59+
}],
60+
card: "summary_large_image",
61+
title: "ArsenTech's Official Blog Website",
62+
description: "Your go-to hub for tech tutorials, antivirus comparisons, and in-depth guides for programmers, tech enthusiasts, and more tech related curious minds.",
63+
},
4164
};
4265

4366
export const viewport: Viewport = {

‎src/app/posts/[slug]/page.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const generateMetadata = async({params}: SinglePostPageProps): Promise<Me
2121
const {slug} = await params;
2222
const currPost = await getPostBySlug(slug);
2323
if(!currPost || !currPost.published) return notFound();
24-
const ogImage = absoluteURL(`/api/og?title=${encodeURIComponent(currPost.title)}&description=${encodeURIComponent(currPost.description)}&date=${currPost.date.toISOString()}`)
24+
const ogImage = absoluteURL(`/api/og?title=${encodeURIComponent(currPost.title)}&description=${encodeURIComponent(currPost.description)}&date=${currPost.date.toISOString()}&bg=image`)
2525
return {
2626
title: currPost.title,
2727
description: currPost.description,

‎src/app/tags/[tag]/page.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ export const generateMetadata = async({params, searchParams}: PageProps): Promis
2727
const currentPage = page ? parseInt(page) : 1;
2828
const postsPerPage = pageSize ? parseInt(pageSize) : POSTS_IN_SEARCH;
2929
const totalPages = Math.ceil(results.length / postsPerPage)
30-
const now = new Date()
31-
32-
const meta = {
30+
const now = new Date(), meta = {
3331
title: `Top ${results.length} posts tagged with "${tagDecoded}" - Updated ${now.getFullYear()}`,
3432
description: `Explore ${results.length} blog posts tagged with "${tagDecoded}" — from coding tutorials to tech insights`,
3533
}
36-
3734
const ogImage = absoluteURL(`/api/og?title=${encodeURIComponent(meta.title)}&description=${encodeURIComponent(meta.description)}&date=${now.toISOString()}`)
38-
3935
return {
4036
title: meta.title,
4137
description: meta.description,

0 commit comments

Comments
 (0)