generated from open-format/next-js-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor community layout and enhance metadata generation
- Replaced the `getCommunity` function with `fetchCommunity` to streamline data fetching. - Introduced `generateMetadata` function to dynamically create Open Graph and Twitter card metadata based on community data. - Added a new API route for generating OG images with customizable titles and accent colors. - Improved layout styling to support dark mode and responsive design. - Removed obsolete color adjustment function to simplify the codebase.
- Loading branch information
1 parent
f2869a2
commit c803e75
Showing
2 changed files
with
103 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getContrastSafeColor } from "@/lib/utils"; | ||
import { ImageResponse } from "next/og"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export async function GET(request: Request) { | ||
try { | ||
const { searchParams } = new URL(request.url); | ||
const title = searchParams.get("title") ?? "Community"; | ||
const accent = searchParams.get("accent") ?? "#6366F1"; | ||
|
||
// Simple gradient using the accent color (similar to community banner) | ||
const gradient = `linear-gradient(45deg, ${accent}, ${accent}88)`; | ||
|
||
return new ImageResponse( | ||
( | ||
<div | ||
style={{ | ||
height: "100%", | ||
width: "100%", | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "flex-start", // Align to the left | ||
justifyContent: "flex-end", // Align to the bottom | ||
background: gradient, | ||
fontFamily: "Manrope", | ||
padding: "48px", // Add some padding | ||
}} | ||
> | ||
<div | ||
style={{ | ||
fontSize: 72, | ||
fontWeight: 700, | ||
color: getContrastSafeColor(accent), | ||
textAlign: "left", | ||
lineHeight: 1.1, | ||
textShadow: "0 2px 4px rgba(0,0,0,0.1)", | ||
}} | ||
> | ||
{title} | ||
</div> | ||
</div> | ||
), | ||
{ | ||
width: 1200, | ||
height: 630, | ||
} | ||
); | ||
} catch (e) { | ||
console.log(`${e.message}`); | ||
return new Response(`Failed to generate the image`, { | ||
status: 500, | ||
}); | ||
} | ||
} |