Fallback to artifact_uri?
Opened this issue · 0 comments
Zir0h commented
Hi! https://teia.art/objkt/2371 does not contain the image link, because only artifact_uri is filled in on the indexer, and the graphql query checks disaply_uri.
On I've done this on https://teia.rocks/objkt/2371 :
diff --git a/src/index.js b/src/index.js
index e9cf537..a97843c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -13,6 +13,7 @@ async function getTokenDetails(tokenId) {
title
description
display_uri
+ artifact_uri
}
}
`,
@@ -37,20 +38,21 @@ function injectOpenGraphTags(body, token, originalUrl) {
const title = clean(token.title);
const description = clean(token.description);
const image = clean(token.display_uri.replace('ipfs://', IPFS_GATEWAY));
+ const image_backup = clean(token.artifact_uri.replace('ipfs://', IPFS_GATEWAY));
const url = `${originalUrl.protocol}//${originalUrl.hostname}/objkt/${token.id}`;
const openGraphTags = `
<meta property="og:type" content="website" />
<meta property="og:title" content="${title}" />
<meta property="og:description" content="${description}" />
- <meta property="og:image" content="${image}" />
+ <meta property="og:image" content="${image ? image : image_backup}" />
<meta property="og:url" content="${url}" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content="@TeiaCommunity" />
<meta name="twitter:title" content="${title}" />
<meta name="twitter:description" content="${description}" />
- <meta name="twitter:image" content="${image}" />
+ <meta name="twitter:image" content="${image ? image : image_backup}" />
`;
return newBody.replace('<head>', `<head>${openGraphTags}`);
Which seems to work, but I'm asking here just to be sure. There's probably a cleaner way 😅