Merge pull request #261 from lbryio/undefined-og-description
Undefined og description
This commit is contained in:
commit
a9685951af
2 changed files with 54 additions and 54 deletions
|
@ -204,7 +204,7 @@ module.exports = {
|
||||||
} else {
|
} else {
|
||||||
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
|
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
// add stats table
|
// add a record to the stats table
|
||||||
postToStats(method, originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
postToStats(method, originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
||||||
// serve or show
|
// serve or show
|
||||||
switch (method) {
|
switch (method) {
|
||||||
|
@ -213,8 +213,17 @@ module.exports = {
|
||||||
sendGoogleAnalytics(method, headers, ip, originalUrl);
|
sendGoogleAnalytics(method, headers, ip, originalUrl);
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
case SHOWLITE:
|
case SHOWLITE:
|
||||||
|
return db.Claim.resolveClaim(fileInfo.name, fileInfo.claimId)
|
||||||
|
.then(claimRecord => {
|
||||||
|
fileInfo['title'] = claimRecord.title;
|
||||||
|
fileInfo['description'] = claimRecord.description;
|
||||||
showFileLite(fileInfo, res);
|
showFileLite(fileInfo, res);
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
logger.error('throwing serverOrShowAsset SHOWLITE error...');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
case SHOW:
|
case SHOW:
|
||||||
return db.Claim
|
return db.Claim
|
||||||
.getShortClaimIdFromLongClaimId(fileInfo.claimId, fileInfo.name)
|
.getShortClaimIdFromLongClaimId(fileInfo.claimId, fileInfo.name)
|
||||||
|
@ -233,7 +242,7 @@ module.exports = {
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.error('throwing serve/show error...');
|
logger.error('throwing serverOrShowAsset SHOW error...');
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2,71 +2,62 @@ const Handlebars = require('handlebars');
|
||||||
const config = require('../config/speechConfig.js');
|
const config = require('../config/speechConfig.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// define any extra helpers you may need
|
|
||||||
googleAnalytics () {
|
googleAnalytics () {
|
||||||
const googleApiKey = config.analytics.googleId;
|
const googleApiKey = config.analytics.googleId;
|
||||||
return new Handlebars.SafeString(
|
const gaCode = `<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
`<script>
|
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||||
ga('create', '${googleApiKey}', 'auto');
|
ga('create', '${googleApiKey}', 'auto');
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');</script>`;
|
||||||
</script>`
|
return new Handlebars.SafeString(gaCode);
|
||||||
);
|
|
||||||
},
|
},
|
||||||
addOpenGraph (title, mimeType, showUrl, source, description, thumbnail) {
|
addOpenGraph (title, mimeType, showUrl, source, description, thumbnail) {
|
||||||
let basicTags = `<meta property="og:title" content="${title}">
|
if (title === null || title.trim() === '') {
|
||||||
<meta property="og:url" content="${showUrl}" >
|
title = 'Spee.ch';
|
||||||
<meta property="og:site_name" content="Spee.ch" >
|
}
|
||||||
<meta property="og:description" content="${description}">`;
|
if (description === null || description.trim() === '') {
|
||||||
|
description = 'Open-source, decentralized image and video sharing.';
|
||||||
|
}
|
||||||
|
const ogTitle = `<meta property="og:title" content="${title}" >`;
|
||||||
|
const ogUrl = `<meta property="og:url" content="${showUrl}" >`;
|
||||||
|
const ogSiteName = `<meta property="og:site_name" content="Spee.ch" >`;
|
||||||
|
const ogDescription = `<meta property="og:description" content="${description}" >`;
|
||||||
|
const ogImageWidth = '<meta property="og:image:width" content="600" >';
|
||||||
|
const ogImageHeight = '<meta property="og:image:height" content="315" >';
|
||||||
|
const basicTags = `${ogTitle} ${ogUrl} ${ogSiteName} ${ogDescription} ${ogImageWidth} ${ogImageHeight}`;
|
||||||
|
let ogImage = `<meta property="og:image" content="${source}" >`;
|
||||||
|
let ogImageType = `<meta property="og:image:type" content="${mimeType}" >`;
|
||||||
|
let ogType = `<meta property="og:type" content="article" >`;
|
||||||
if (mimeType === 'video/mp4') {
|
if (mimeType === 'video/mp4') {
|
||||||
return new Handlebars.SafeString(
|
const ogVideo = `<meta property="og:video" content="${source}" >`;
|
||||||
`${basicTags} <meta property="og:image" content="${thumbnail}" >
|
const ogVideoSecureUrl = `<meta property="og:video:secure_url" content="${source}" >`;
|
||||||
<meta property="og:image:type" content="image/png" >
|
const ogVideoType = `<meta property="og:video:type" content="${mimeType}" >`;
|
||||||
<meta property="og:image:width" content="600" >
|
ogImage = `<meta property="og:image" content="${thumbnail}" >`;
|
||||||
<meta property="og:image:height" content="315" >
|
ogImageType = `<meta property="og:image:type" content="image/png" >`;
|
||||||
<meta property="og:type" content="video" >
|
ogType = `<meta property="og:type" content="video" >`;
|
||||||
<meta property="og:video" content="${source}" >
|
return new Handlebars.SafeString(`${basicTags} ${ogImage} ${ogImageType} ${ogType} ${ogVideo} ${ogVideoSecureUrl} ${ogVideoType}`);
|
||||||
<meta property="og:video:secure_url" content="${source}" >
|
|
||||||
<meta property="og:video:type" content="${mimeType}" >`
|
|
||||||
);
|
|
||||||
} else if (mimeType === 'image/gif') {
|
|
||||||
return new Handlebars.SafeString(
|
|
||||||
`${basicTags} <meta property="og:image" content="${source}" >
|
|
||||||
<meta property="og:image:type" content="${mimeType}" >
|
|
||||||
<meta property="og:image:width" content="600" >
|
|
||||||
<meta property="og:image:height" content="315" >
|
|
||||||
<meta property="og:type" content="video.other" >`
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return new Handlebars.SafeString(
|
if (mimeType === 'image/gif') {
|
||||||
`${basicTags} <meta property="og:image" content="${source}" >
|
ogType = `<meta property="og:type" content="video.other" >`;
|
||||||
<meta property="og:image:type" content="${mimeType}" >
|
};
|
||||||
<meta property="og:image:width" content="600" >
|
return new Handlebars.SafeString(`${basicTags} ${ogImage} ${ogImageType} ${ogType}`);
|
||||||
<meta property="og:image:height" content="315" >
|
|
||||||
<meta property="og:type" content="article" >`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addTwitterCard (mimeType, source, embedUrl, directFileUrl) {
|
addTwitterCard (mimeType, source, embedUrl, directFileUrl) {
|
||||||
let basicTwitterTags = `<meta name="twitter:site" content="@spee_ch" >`;
|
const basicTwitterTags = `<meta name="twitter:site" content="@spee_ch" >`;
|
||||||
if (mimeType === 'video/mp4') {
|
if (mimeType === 'video/mp4') {
|
||||||
return new Handlebars.SafeString(
|
const twitterName = '<meta name="twitter:card" content="player" >';
|
||||||
`${basicTwitterTags} <meta name="twitter:card" content="player" >
|
const twitterPlayer = `<meta name="twitter:player" content="${embedUrl}" >`;
|
||||||
<meta name="twitter:player" content="${embedUrl}>
|
const twitterPlayerWidth = '<meta name="twitter:player:width" content="600" >';
|
||||||
<meta name="twitter:player:width" content="600" >
|
const twitterTextPlayerWidth = '<meta name="twitter:text:player_width" content="600" >';
|
||||||
<meta name="twitter:text:player_width" content="600" >
|
const twitterPlayerHeight = '<meta name="twitter:player:height" content="337" >';
|
||||||
<meta name="twitter:player:height" content="337" >
|
const twitterPlayerStream = `<meta name="twitter:player:stream" content="${directFileUrl}" >`;
|
||||||
<meta name="twitter:player:stream" content="${directFileUrl}" >
|
const twitterPlayerStreamContentType = '<meta name="twitter:player:stream:content_type" content="video/mp4" >';
|
||||||
<meta name="twitter:player:stream:content_type" content="video/mp4" >
|
return new Handlebars.SafeString(`${basicTwitterTags} ${twitterName} ${twitterPlayer} ${twitterPlayerWidth} ${twitterTextPlayerWidth} ${twitterPlayerHeight} ${twitterPlayerStream} ${twitterPlayerStreamContentType}`);
|
||||||
`
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return new Handlebars.SafeString(
|
const twitterCard = '<meta name="twitter:card" content="summary_large_image" >';
|
||||||
`${basicTwitterTags} <meta name="twitter:card" content="summary_large_image" >`
|
return new Handlebars.SafeString(`${basicTwitterTags} ${twitterCard}`);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ifConditional (varOne, operator, varTwo, options) {
|
ifConditional (varOne, operator, varTwo, options) {
|
||||||
|
|
Loading…
Reference in a new issue