Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/adding ogimage to app #56

Open
wants to merge 41 commits into
base: favicon-cover-image
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2e1de34
changes : change for deployement
faisal004 Dec 19, 2024
dcbf976
changes
faisal004 Dec 19, 2024
b155421
added : og image
faisal004 Dec 19, 2024
40a8838
added : dyanmic og image generation added
faisal004 Dec 23, 2024
ac63fce
fix : og image fixed
faisal004 Dec 23, 2024
2cc2ac5
fix : og image from db
faisal004 Dec 23, 2024
81f1c0b
fix : console removed
faisal004 Dec 23, 2024
b066cf0
Merge branch 'main' of https://github.com/tyaga001/devtoolsacademy in…
faisal004 Jan 2, 2025
0941247
Merge branch 'tyaga001-main'
faisal004 Jan 2, 2025
d59ee5c
fix : conflix fixed
faisal004 Jan 2, 2025
c1049ac
added : og iamge preview
faisal004 Jan 2, 2025
4e311b9
fix : eslint rule
faisal004 Jan 2, 2025
0ef326d
changes
faisal004 Jan 3, 2025
9dde11e
added : url fallback
faisal004 Jan 3, 2025
ed45aae
changes : for local deployment
faisal004 Feb 8, 2025
e25a063
changes : for local deployment
faisal004 Feb 8, 2025
9ff88ef
adding : og image
faisal004 Feb 8, 2025
9c588e3
fix : url path fix
faisal004 Feb 8, 2025
21d16ec
just for testing will revert it
faisal004 Feb 8, 2025
3d2699d
adding : dynamic og iamge to /blog
faisal004 Feb 8, 2025
acac98d
adding : dynamic og iamge to /blog
faisal004 Feb 8, 2025
85c9560
added : dynamic og image to routes
faisal004 Feb 8, 2025
6622adc
reverting back to original url
faisal004 Feb 8, 2025
26cfd98
Merge branch 'main' of https://github.com/faisal004/devtoolsacademy i…
faisal004 Feb 8, 2025
246964e
remove env as config file handled that
faisal004 Feb 8, 2025
38096ed
for check
faisal004 Feb 8, 2025
bd711cc
removed cover and added dynamic image
faisal004 Feb 10, 2025
f122db4
removed cover and added dynamic image - 2
faisal004 Feb 10, 2025
384033e
url changed back
faisal004 Feb 10, 2025
edd2bd6
url for test
faisal004 Feb 10, 2025
2b96735
Delete public/cover.png
faisal004 Feb 10, 2025
cd9a08a
Favicon and website og image (#96)
nirnejak Feb 26, 2025
6d5a3c3
Merge branch 'favicon-cover-image' into feature/adding-ogimage-to-app
faisal004 Feb 26, 2025
b5775d9
Merge branch 'main' of https://github.com/faisal004/devtoolsacademy i…
faisal004 Feb 26, 2025
71e364f
fix
faisal004 Feb 26, 2025
91e857a
Merge branch 'main' of https://github.com/faisal004/devtoolsacademy
faisal004 Feb 26, 2025
42b1e08
fix
faisal004 Feb 26, 2025
40ac873
Merge branch 'main' of https://github.com/faisal004/devtoolsacademy i…
faisal004 Feb 26, 2025
4af98c2
fix : for ig image
faisal004 Feb 26, 2025
6204bc3
fix : for og image
faisal004 Feb 26, 2025
61ea83c
Merge branch 'main' of https://github.com/faisal004/devtoolsacademy i…
faisal004 Feb 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXT_PUBLIC_BASE_URL=https://www.devtoolsacademy.com
DATABASE_URL=
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"lint": "next lint",
"migrate": "npx prisma migrate dev --schema=./prisma/schema.prisma",
"db-create": "npx prisma db push --schema=./prisma/schema.prisma",
"format": "prettier --write --ignore-path .gitignore ."
"format": "prettier --write --ignore-path .gitignore .",
"postinstall": "prisma generate"
},
"dependencies": {
"@clerk/nextjs": "^5.2.4",
Expand Down
Binary file added public/og-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/og-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions src/app/api/og/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { ImageResponse } from "next/og"
import { NextRequest } from "next/server"

export async function GET(req: NextRequest) {
const { searchParams } = req.nextUrl
const postTitle = searchParams.get("title")

return new (ImageResponse as any)(
(
<div
style={{
height: "100%",
width: "100%",
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "center",
backgroundImage: `url("${process.env.NEXT_PUBLIC_BASE_URL}/og-bg.png")`,
}}
>
<h1 tw="absolute inset-0 flex justify-center items-center mb-96 flex-row">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
tw="h-10 w-10"
alt="Alt"
// @ts-ignore
src={`${process.env.NEXT_PUBLIC_BASE_URL}/favicon.png`}
/>
<span
tw="ml-3"
style={{
background:
"linear-gradient(180deg, rgba(255,255,255,1) 0%, rgba(156, 163, 175, 1) 100%)",
backgroundClip: "text",
WebkitBackgroundClip: "text",
color: "transparent",
fontSize: 35,
letterSpacing: "-1.5px",
}}
>
DevToolsAcademy
</span>
</h1>

{postTitle && (
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
height: "100vh",
width: "100vw",
}}
>
<p
style={{
whiteSpace: "pre-wrap",
alignContent: "center",
justifyContent: "center",
background:
"linear-gradient(180deg, rgba(105, 105, 105, 1) 0%, rgba(211, 211, 211, 1) 100%)",
backgroundClip: "text",
WebkitBackgroundClip: "text",
textAlign: "center",
fontSize: 100,
letterSpacing: "-5px",
color: "transparent",
WebkitTextFillColor: "transparent",
}}
>
{postTitle}
</p>
</div>
)}

<h1 tw="absolute inset-0 flex justify-center items-center mt-57 flex-col">
<span
style={{
background:
"linear-gradient(180deg, rgba(255,255,255,1) 0%, rgba(156, 163, 175, 1) 100%)",
// "linear-gradient(180deg,rgba(240,238,249,.8) 0%,#E2E8FF 100%)",
backgroundClip: "text",
WebkitBackgroundClip: "text",
color: "transparent",
fontSize: 50,
letterSpacing: "-1.5px",
marginTop: 150,
}}
>
A special blog made for Developers.
</span>
</h1>
</div>
),
{
width: 1920,
height: 1080,
}
)
}
46 changes: 46 additions & 0 deletions src/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import BackToTop from "@/components/BackToTop"
import ScrollProgressBar from "@/components/ScrollProgressBar"
import { cn } from "@/lib/utils"
import { SocialMetadata } from "@/components/SocialMetadata"
import { Metadata } from "next"

const components: MDXComponents = {
h1: (props: any) => <h1 {...props}>{props.children}</h1>,
Expand Down Expand Up @@ -103,6 +104,51 @@ const components: MDXComponents = {

const baseUrl = "https://devtoolsacademy.com"

export async function generateMetadata({
params,
}: {
params: { slug: string }
}): Promise<Metadata> {
const post = await getPostBySlug(params.slug)
if (!post) {
return {}
}
const { title, featuredImage } = post
const ogImage = featuredImage
? featuredImage
: `${process.env.NEXT_PUBLIC_BASE_URL}/api/og?title=${post.title}`
return {
title: `${post.title} | Dev Tools Academy`,
description: post.description,
openGraph: {
title: post.title,
description: post.description,
type: "article",
url: `${process.env.NEXT_PUBLIC_BASE_URL}/${post.slug}`,
images: [
{
url: ogImage,
width: 1200,
height: 630,
alt: "Dev Tools Academy",
},
],
},
twitter: {
card: "summary_large_image",
title: post.title,
description: post.description,
images: [
{
url: ogImage,
width: 1200,
height: 630,
alt: title,
},
],
},
}
}
export default async function BlogPost({
params,
}: {
Expand Down
32 changes: 32 additions & 0 deletions src/app/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@ import Link from "next/link"

import { getAllPosts } from "@/lib/posts"
import { formatDate } from "@/lib/utils"
import { Metadata } from "next"

export const metadata: Metadata = {
title: "Blogs | Dev Tools Academy",
description: "A special blog made for Developers.",
openGraph: {
title: "Blogs | Dev Tools Academy",
description: "A special blog made for Developers.",
url: process.env.NEXT_PUBLIC_BASE_URL,
images: [
{
url: `${process.env.NEXT_PUBLIC_BASE_URL}/api/og?title=Blogs%20|%20DevToolsAcademy`,
width: 1200,
height: 639,
alt: "DevToolsAcademy",
},
],
},
twitter: {
card: "summary_large_image",
title: "Blogs | Dev Tools Academy",
description: "A special blog made for Developers.",
images: [
{
url: `${process.env.NEXT_PUBLIC_BASE_URL}/api/og?title=Blogs%20|%20DevToolsAcademy`,
width: 1200,
height: 639,
alt: "DevToolsAcademy",
},
],
},
}

export default async function BlogPage() {
const posts = await getAllPosts()
Expand Down
16 changes: 13 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ export const metadata: Metadata = {
template: "%s | Dev Tools Academy",
},
description: "Learn about awesome developer tools",
metadataBase: new URL("https://devtoolsacademy.com"),
metadataBase: new URL(`${process.env.NEXT_PUBLIC_BASE_URL}`),
openGraph: {
title: "Dev Tools Academy",
description: "Learn about awesome developer tools",
url: "https://devtoolsacademy.com",
url: process.env.NEXT_PUBLIC_BASE_URL ?? "https://devtoolsacademy.com",
siteName: "Dev Tools Academy",
locale: "en_US",
type: "website",
images: [
{
url: `${process.env.NEXT_PUBLIC_BASE_URL}/og-image.png`,
width: 1200,
height: 639,
alt: "Dev Tools Academ",
},
],
},
twitter: {
card: "summary_large_image",
Expand Down Expand Up @@ -83,7 +91,9 @@ export default function RootLayout({ children }: RootLayoutProps) {
url={
metadata.metadataBase?.toString() ?? "https://devtoolsacademy.com"
}
image={`${metadata.metadataBase?.toString() ?? "https://devtoolsacademy.com"}/favicon.png`}
image={`${
metadata.metadataBase?.toString() ?? "https://devtoolsacademy.com"
}/favicon.png`}
type="website"
/>
<Script
Expand Down