added thumbnail content type to og metadata

This commit is contained in:
bill bittner 2017-12-06 14:47:50 -08:00
parent ac610af6af
commit 478b8983fa
2 changed files with 27 additions and 2 deletions

View file

@ -12,7 +12,7 @@ module.exports = {
ga('send', 'pageview');</script>`;
return new Handlebars.SafeString(gaCode);
},
addOpenGraph ({ ogTitle, contentType, ogDescription, thumbnail, showUrl, source }) {
addOpenGraph ({ ogTitle, contentType, ogDescription, thumbnail, showUrl, source, ogThumbnailContentType }) {
const ogTitleTag = `<meta property="og:title" content="${ogTitle}" >`;
const ogUrlTag = `<meta property="og:url" content="${showUrl}" >`;
const ogSiteNameTag = `<meta property="og:site_name" content="Spee.ch" >`;
@ -28,7 +28,7 @@ module.exports = {
const ogVideoSecureUrlTag = `<meta property="og:video:secure_url" content="${source}" >`;
const ogVideoTypeTag = `<meta property="og:video:type" content="${contentType}" >`;
ogImageTag = `<meta property="og:image" content="${thumbnail}" >`;
// ogImageTypeTag = `<meta property="og:image:type" content="image/png" >`; // note: might not be png. needs to check if gif or jpg etc depending on thubmnail
ogImageTypeTag = `<meta property="og:image:type" content="${ogThumbnailContentType}" >`;
ogTypeTag = `<meta property="og:type" content="video" >`;
return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag} ${ogVideoTag} ${ogVideoSecureUrlTag} ${ogVideoTypeTag}`);
} else {

View file

@ -21,6 +21,23 @@ function determineFileExtensionFromContentType (contentType) {
}
};
function determineContentTypeFromFileExtension (fileExtension) {
switch (fileExtension) {
case 'jpeg':
case 'jpg':
return 'image/jpg';
case 'png':
return 'image/png';
case 'gif':
return 'image/gif';
case 'mp4':
return 'video/mp4';
default:
logger.info('setting unknown file type as type image/jpg');
return 'image/jpg';
}
};
function ifEmptyReturnOther (value, replacement) {
if (value === '') {
return replacement;
@ -40,6 +57,13 @@ function determineOgDescription (storedDescription, defaultDescription) {
return ifEmptyReturnOther(storedDescription, defaultDescription);
};
function determineOgThumbnailContentType (thumbnail) {
if (thumbnail.lastIndexOf('.') !== -1) {
return determineContentTypeFromFileExtension(thumbnail.substring(thumbnail.lastIndexOf('.')));
}
return '';
}
function addOpengraphDataToClaim (claim) {
claim['embedUrl'] = `https://spee.ch/embed/${claim.claimId}/${claim.name}`;
claim['showUrl'] = `https://spee.ch/${claim.claimId}/${claim.name}`;
@ -47,6 +71,7 @@ function addOpengraphDataToClaim (claim) {
claim['directFileUrl'] = `https://spee.ch/${claim.claimId}/${claim.name}.${claim.fileExt}`;
claim['ogTitle'] = determineOgTitle(claim.title, DEFAULT_TITLE);
claim['ogDescription'] = determineOgDescription(claim.description, DEFAULT_DESCRIPTION);
claim['ogThumbnailContentType'] = determineOgThumbnailContentType(claim.thumbnail);
};
function prepareClaimData (claimData) {