Created
March 29, 2018 16:23
-
-
Save furkan3ayraktar/a5d67453d3680e9845269978ea89840e to your computer and use it in GitHub Desktop.
Function for fetching metadata from backend.
This file contains hidden or 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
const fetchMetaData = (url, callback) => { | |
downloadContent(url, (isOk, result, headers) => { | |
if (!isOk) { | |
console.log('Error fetching meta data:', result); | |
callback(false); | |
} else { | |
const metaData = JSON.parse(result); | |
let metaTags = ''; | |
if (metaData) { | |
if (metaData.title) { | |
metaTags += '<title>' + metaData.title + '</title>'; | |
metaTags += '<meta property=\"og:title\" content=\"' + metaData.title + '\" />'; | |
} | |
if (metaData.description) { | |
metaTags += '<meta name=\"description\" content=\"' + metaData.description + '\" />'; | |
metaTags += '<meta property=\"og:description\" content=\"' + metaData.description + '\" />'; | |
} | |
if (metaData.images) { | |
for (let i = 0; i < metaData.images.length; i++) { | |
const image = metaData.images[i]; | |
metaTags += '<meta property=\"og:image\" content=\"' + image + '\" />'; | |
} | |
} | |
} | |
metaTags += '<meta property=\"og:url\" content=\"https://' + domainName + originalUri + '\" />'; | |
metaTags += '<meta property=\"og:type\" content=\"website\" />'; | |
callback(true, metaTags, headers); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment