Development #287

Merged
bones7242 merged 58 commits from development into master 2017-12-11 20:53:02 +01:00
4 changed files with 30 additions and 27 deletions
Showing only changes of commit 0bf162d832 - Show all commits

View file

@ -12,7 +12,7 @@ module.exports = {
ga('send', 'pageview');</script>`;
return new Handlebars.SafeString(gaCode);
},
addOpenGraph (title, mimeType, showUrl, source, description, thumbnail) {
addOpenGraph ({ title, contentType, description, thumbnail, showUrl, source }) {
if (!title || title.trim() === '') {
title = 'Spee.ch';
}
@ -27,26 +27,26 @@ module.exports = {
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 ogImageType = `<meta property="og:image:type" content="${contentType}" >`;
let ogType = `<meta property="og:type" content="article" >`;
if (mimeType === 'video/mp4') {
if (contentType === 'video/mp4') {
const ogVideo = `<meta property="og:video" content="${source}" >`;
const ogVideoSecureUrl = `<meta property="og:video:secure_url" content="${source}" >`;
const ogVideoType = `<meta property="og:video:type" content="${mimeType}" >`;
const ogVideoType = `<meta property="og:video:type" content="${contentType}" >`;
ogImage = `<meta property="og:image" content="${thumbnail}" >`;
ogImageType = `<meta property="og:image:type" content="image/png" >`;
ogType = `<meta property="og:type" content="video" >`;
return new Handlebars.SafeString(`${basicTags} ${ogImage} ${ogImageType} ${ogType} ${ogVideo} ${ogVideoSecureUrl} ${ogVideoType}`);
} else {
if (mimeType === 'image/gif') {
if (contentType === 'image/gif') {
ogType = `<meta property="og:type" content="video.other" >`;
};
return new Handlebars.SafeString(`${basicTags} ${ogImage} ${ogImageType} ${ogType}`);
}
},
addTwitterCard (mimeType, source, embedUrl, directFileUrl) {
addTwitterCard ({ contentType, source, embedUrl, directFileUrl }) {
const basicTwitterTags = `<meta name="twitter:site" content="@spee_ch" >`;
if (mimeType === 'video/mp4') {
if (contentType === 'video/mp4') {
const twitterName = '<meta name="twitter:card" content="player" >';
const twitterPlayer = `<meta name="twitter:player" content="${embedUrl}" >`;
const twitterPlayerWidth = '<meta name="twitter:player:width" content="600" >';

View file

@ -23,12 +23,4 @@ module.exports = {
const openGraphInfo = module.exports.createOpenGraphInfo(claimInfo);
res.status(200).render('showLite', { layout: 'showlite', claimInfo, shortId, openGraphInfo });
},
createOpenGraphInfo ({ claimId, name, fileExt }) {
return {
embedUrl : `https://spee.ch/embed/${claimId}/${name}`,
showUrl : `https://spee.ch/${claimId}/${name}`,
source : `https://spee.ch/${claimId}/${name}.${fileExt}`,
directFileUrl: `https://spee.ch/${claimId}/${name}.${fileExt}`,
};
},
};

View file

@ -26,6 +26,20 @@ function determineThumbnail (storedThumbnail, defaultThumbnail) {
return storedThumbnail;
};
function addOpengraphDataToClaim (claim) {
claim['embedUrl'] = `https://spee.ch/embed/${claim.claimId}/${claim.name}`;
claim['showUrl'] = `https://spee.ch/${claim.claimId}/${claim.name}`;
claim['source'] = `https://spee.ch/${claim.claimId}/${claim.name}.${claim.fileExt}`;
claim['directFileUrl'] = `https://spee.ch/${claim.claimId}/${claim.name}.${claim.fileExt}`;
};
function prepareClaimData (claimData) {
claimData['thumbnail'] = determineThumbnail(claimData.thumbnail, DEFAULT_THUMBNAIL);
claimData['fileExt'] = determineFileExtensionFromContentType(claimData.contentType);
claimData = addOpengraphDataToClaim(claimData);
return claimData;
};
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
const Claim = sequelize.define(
'Claim',
@ -337,18 +351,15 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
.findAll({
where: { name, claimId },
})
.then(result => {
if (!result) {
return resolve(null);
};
switch (result.length) {
.then(claimArray => {
switch (claimArray.length) {
case 0:
return resolve(null);
case 1:
result[0].dataValues.thumbnail = determineThumbnail(result[0].dataValues.thumbnail, DEFAULT_THUMBNAIL);
result[0].dataValues.fileExt = determineFileExtensionFromContentType(result[0].dataValues.contentType);
return resolve(result[0]);
return resolve(prepareClaimData(claimArray[0].dataValues));
default:
logger.warn(`more than one entry matches that name (${name}) and claimID (${claimId})`);
return resolve(result[0]);
logger.error(`more than one entry matches that name (${name}) and claimID (${claimId})`);
return resolve(prepareClaimData(claimArray[0].dataValues));
}
})
.catch(error => {

View file

@ -10,8 +10,8 @@
<link rel="stylesheet" href="/assets/css/mediaQueries.css" type="text/css">
<meta property="fb:app_id" content="1371961932852223">
{{#unless claimInfo.nsfw}}
{{{addTwitterCard claimInfo.contentType openGraphInfo.source openGraphInfo.embedUrl openGraphInfo.directFileUrl}}}
{{{addOpenGraph claimInfo.title claimInfo.contentType openGraphInfo.showUrl openGraphInfo.source claimInfo.description claimInfo.thumbnail}}}
{{{addTwitterCard claimInfo }}}
{{{addOpenGraph claimInfo }}}
{{/unless}}
<!--google font-->
<link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">