-
-
Notifications
You must be signed in to change notification settings - Fork 37.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace with og endpoint (#5571)
* chore: replace with og endpoint * fix: update og routes
- Loading branch information
1 parent
d441c9a
commit b7a8588
Showing
12 changed files
with
121 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
type RoadmapOpenGraphQuery = { | ||
group: 'roadmaps' | 'guides' | 'best-practices'; | ||
group: 'roadmap' | 'guide' | 'best-practice'; | ||
resourceId: string; | ||
}; | ||
|
||
export function getOpenGraphImageUrl(params: RoadmapOpenGraphQuery) { | ||
return `${import.meta.env.DEV ? 'http://localhost:3000' : 'https://roadmap.sh'}/og-images/${params.group}/${params.resourceId}.png`; | ||
return `${import.meta.env.DEV ? 'http://localhost:3000' : 'https://roadmap.sh'}/og/${params.group}/${params.resourceId}`; | ||
} | ||
|
||
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()); | ||
} | ||
|
||
export async function getResourceOpenGraph( | ||
type: 'roadmap' | 'guide' | 'best-practice', | ||
resourceId: string, | ||
) { | ||
const url = new URL(`${import.meta.env.PUBLIC_API_URL}/v1-open-graph`); | ||
url.searchParams.set('type', type); | ||
url.searchParams.set('resourceId', resourceId); | ||
url.searchParams.set('variant', 'image'); | ||
const response = await fetch(url.toString()); | ||
|
||
return response.text(); | ||
} |
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
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
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
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,31 @@ | ||
import type { APIRoute } from 'astro'; | ||
import { | ||
getDefaultOpenGraphImageBuffer, | ||
getResourceOpenGraph, | ||
} from '../../../lib/open-graph'; | ||
|
||
export const prerender = false; | ||
|
||
type Params = { | ||
slug: string; | ||
}; | ||
|
||
export const GET: APIRoute<any, Params> = async (context) => { | ||
const { slug } = context.params; | ||
|
||
if (!slug) { | ||
const buffer = await getDefaultOpenGraphImageBuffer(); | ||
return new Response(buffer, { | ||
headers: { | ||
'Content-Type': 'image/png', | ||
}, | ||
}); | ||
} | ||
|
||
const svg = await getResourceOpenGraph('best-practice', slug); | ||
return new Response(svg, { | ||
headers: { | ||
'Content-Type': 'image/svg+xml', | ||
}, | ||
}); | ||
}; |
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,31 @@ | ||
import type { APIRoute } from 'astro'; | ||
import { | ||
getDefaultOpenGraphImageBuffer, | ||
getResourceOpenGraph, | ||
} from '../../../lib/open-graph'; | ||
|
||
export const prerender = false; | ||
|
||
type Params = { | ||
slug: string; | ||
}; | ||
|
||
export const GET: APIRoute<any, Params> = async (context) => { | ||
const { slug } = context.params; | ||
|
||
if (!slug) { | ||
const buffer = await getDefaultOpenGraphImageBuffer(); | ||
return new Response(buffer, { | ||
headers: { | ||
'Content-Type': 'image/png', | ||
}, | ||
}); | ||
} | ||
|
||
const svg = await getResourceOpenGraph('guide', slug); | ||
return new Response(svg, { | ||
headers: { | ||
'Content-Type': 'image/svg+xml', | ||
}, | ||
}); | ||
}; |
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,31 @@ | ||
import type { APIRoute } from 'astro'; | ||
import { | ||
getDefaultOpenGraphImageBuffer, | ||
getResourceOpenGraph, | ||
} from '../../../lib/open-graph'; | ||
|
||
export const prerender = false; | ||
|
||
type Params = { | ||
slug: string; | ||
}; | ||
|
||
export const GET: APIRoute<any, Params> = async (context) => { | ||
const { slug } = context.params; | ||
|
||
if (!slug) { | ||
const buffer = await getDefaultOpenGraphImageBuffer(); | ||
return new Response(buffer, { | ||
headers: { | ||
'Content-Type': 'image/png', | ||
}, | ||
}); | ||
} | ||
|
||
const svg = await getResourceOpenGraph('roadmap', slug); | ||
return new Response(svg, { | ||
headers: { | ||
'Content-Type': 'image/svg+xml', | ||
}, | ||
}); | ||
}; |
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