mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-19 07:31:24 +02:00
Add default opengraph on error (#5552)
This commit is contained in:
@@ -6,3 +6,8 @@ type RoadmapOpenGraphQuery = {
|
||||
export function getOpenGraphImageUrl(params: RoadmapOpenGraphQuery) {
|
||||
return `${import.meta.env.DEV ? 'http://localhost:3000' : 'https://roadmap.sh'}/og-images/${params.group}/${params.resourceId}.png`;
|
||||
}
|
||||
|
||||
export async function getDefaultOpenGraphImageBuffer() {
|
||||
const defaultImageUrl = `${import.meta.env.DEV ? 'http://localhost:3000' : 'https://roadmap.sh'}/images/og-img.png`;
|
||||
return fetch(defaultImageUrl).then((response) => response.arrayBuffer());
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { getDefaultOpenGraphImageBuffer } from '../../lib/open-graph';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
@@ -10,26 +11,22 @@ export const GET: APIRoute<any, Params> = async (context) => {
|
||||
const { slug } = context.params;
|
||||
|
||||
if (!slug.startsWith('user-')) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: 'Invalid slug',
|
||||
}),
|
||||
{
|
||||
status: 400,
|
||||
const buffer = await getDefaultOpenGraphImageBuffer();
|
||||
return new Response(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const username = slug.replace('user-', '');
|
||||
if (!username) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: 'Invalid username',
|
||||
}),
|
||||
{
|
||||
status: 400,
|
||||
const buffer = await getDefaultOpenGraphImageBuffer();
|
||||
return new Response(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
|
Reference in New Issue
Block a user