Skip to content

Commit

Permalink
Update shop.js
Browse files Browse the repository at this point in the history
Added the data as og tags when the detail view is loaded for that monster
  • Loading branch information
monster-site authored Oct 21, 2024
1 parent eac796e commit 5165e63
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shop/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function loadMonsterDetails() {
var color = data[i]["color"];
var textColor = data[i]["textcolor"];
var text = data[i]["text"];
addOpenGraphMetaTags(data[i]["title"], data[i]["description"], data[i]["image"])
const badge = document.getElementById("details-badge-text");
badge.style.color = textColor;
badge.style.backgroundColor = color;
Expand All @@ -50,6 +51,25 @@ function loadMonsterDetails() {
trackEvent('VIEW_ITEM');
}

function addOpenGraphMetaTags(title, description, image) {
const ogTitle = document.createElement('meta');
ogTitle.setAttribute('property', 'og:title');
ogTitle.setAttribute('content', title);

const ogDescription = document.createElement('meta');
ogDescription.setAttribute('property', 'og:description');
ogDescription.setAttribute('content', description);

const ogImage = document.createElement('meta');
ogImage.setAttribute('property', 'og:image');
ogImage.setAttribute('content', image);

const head = document.getElementsByTagName('head')[0];
head.appendChild(ogTitle);
head.appendChild(ogDescription);
head.appendChild(ogImage);
}

function loadShopItems() {
loadImage("monster-image-1", 0, "monster-badge-1");
loadImage("monster-image-2", 1, "monster-badge-2");
Expand Down

0 comments on commit 5165e63

Please sign in to comment.