forked from Mirrors/elk
Only request opengraph if api key is defined
This commit is contained in:
parent
2c3e0253f6
commit
a4eae9891b
1 changed files with 6 additions and 4 deletions
|
@ -40,12 +40,14 @@ export default defineEventHandler(async (event) => {
|
||||||
const html = await $fetch<string>(cardUrl)
|
const html = await $fetch<string>(cardUrl)
|
||||||
ogImageUrl = extractOgImageUrl(html)
|
ogImageUrl = extractOgImageUrl(html)
|
||||||
|
|
||||||
|
if (process.env.NUXT_OPENGRAPH_API) {
|
||||||
// If no og:image was found, try to get it from opengraph.io
|
// If no og:image was found, try to get it from opengraph.io
|
||||||
if (!ogImageUrl) {
|
if (!ogImageUrl) {
|
||||||
const response = await getOpenGraphClient().getSiteInfo(cardUrl)
|
const response = await getOpenGraphClient().getSiteInfo(cardUrl)
|
||||||
|
|
||||||
ogImageUrl = response?.openGraph?.image?.url ?? ''
|
ogImageUrl = response?.openGraph?.image?.url ?? ''
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(JSON.stringify({ cardUrl, ogImageUrl }))
|
console.log(JSON.stringify({ cardUrl, ogImageUrl }))
|
||||||
|
|
Loading…
Reference in a new issue