2017-09-17 02:50:22 +02:00
|
|
|
const Handlebars = require('handlebars');
|
2017-11-07 00:18:45 +01:00
|
|
|
const config = require('../config/speechConfig.js');
|
2017-09-17 02:50:22 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
googleAnalytics () {
|
2017-11-07 00:18:45 +01:00
|
|
|
const googleApiKey = config.analytics.googleId;
|
2017-11-14 21:32:14 +01:00
|
|
|
const gaCode = `<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
2017-09-17 02:50:22 +02:00
|
|
|
(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)
|
|
|
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', '${googleApiKey}', 'auto');
|
2017-11-14 21:32:14 +01:00
|
|
|
ga('send', 'pageview');</script>`;
|
|
|
|
return new Handlebars.SafeString(gaCode);
|
2017-09-17 02:50:22 +02:00
|
|
|
},
|
2017-12-06 23:47:50 +01:00
|
|
|
addOpenGraph ({ ogTitle, contentType, ogDescription, thumbnail, showUrl, source, ogThumbnailContentType }) {
|
2017-12-06 23:41:03 +01:00
|
|
|
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" >`;
|
|
|
|
const ogDescriptionTag = `<meta property="og:description" content="${ogDescription}" >`;
|
|
|
|
const ogImageWidthTag = '<meta property="og:image:width" content="600" >';
|
|
|
|
const ogImageHeightTag = '<meta property="og:image:height" content="315" >';
|
|
|
|
const basicTags = `${ogTitleTag} ${ogUrlTag} ${ogSiteNameTag} ${ogDescriptionTag} ${ogImageWidthTag} ${ogImageHeightTag}`;
|
|
|
|
let ogImageTag = `<meta property="og:image" content="${source}" >`;
|
|
|
|
let ogImageTypeTag = `<meta property="og:image:type" content="${contentType}" >`;
|
|
|
|
let ogTypeTag = `<meta property="og:type" content="article" >`;
|
2017-12-06 23:23:28 +01:00
|
|
|
if (contentType === 'video/mp4') {
|
2017-12-06 23:41:03 +01:00
|
|
|
const ogVideoTag = `<meta property="og:video" content="${source}" >`;
|
|
|
|
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}" >`;
|
2017-12-06 23:47:50 +01:00
|
|
|
ogImageTypeTag = `<meta property="og:image:type" content="${ogThumbnailContentType}" >`;
|
2017-12-06 23:41:03 +01:00
|
|
|
ogTypeTag = `<meta property="og:type" content="video" >`;
|
|
|
|
return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag} ${ogVideoTag} ${ogVideoSecureUrlTag} ${ogVideoTypeTag}`);
|
2017-09-17 02:50:22 +02:00
|
|
|
} else {
|
2017-12-06 23:23:28 +01:00
|
|
|
if (contentType === 'image/gif') {
|
2017-12-06 23:41:03 +01:00
|
|
|
ogTypeTag = `<meta property="og:type" content="video.other" >`;
|
2017-11-09 23:20:25 +01:00
|
|
|
};
|
2017-12-06 23:41:03 +01:00
|
|
|
return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag}`);
|
2017-09-17 02:50:22 +02:00
|
|
|
}
|
|
|
|
},
|
2017-12-06 23:23:28 +01:00
|
|
|
addTwitterCard ({ contentType, source, embedUrl, directFileUrl }) {
|
2017-11-14 21:32:14 +01:00
|
|
|
const basicTwitterTags = `<meta name="twitter:site" content="@spee_ch" >`;
|
2017-12-06 23:23:28 +01:00
|
|
|
if (contentType === 'video/mp4') {
|
2017-11-14 21:32:14 +01:00
|
|
|
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" >';
|
|
|
|
const twitterTextPlayerWidth = '<meta name="twitter:text:player_width" content="600" >';
|
|
|
|
const twitterPlayerHeight = '<meta name="twitter:player:height" content="337" >';
|
|
|
|
const twitterPlayerStream = `<meta name="twitter:player:stream" content="${directFileUrl}" >`;
|
|
|
|
const twitterPlayerStreamContentType = '<meta name="twitter:player:stream:content_type" content="video/mp4" >';
|
2017-11-09 23:30:13 +01:00
|
|
|
return new Handlebars.SafeString(`${basicTwitterTags} ${twitterName} ${twitterPlayer} ${twitterPlayerWidth} ${twitterTextPlayerWidth} ${twitterPlayerHeight} ${twitterPlayerStream} ${twitterPlayerStreamContentType}`);
|
2017-09-17 02:50:22 +02:00
|
|
|
} else {
|
2017-11-14 21:32:14 +01:00
|
|
|
const twitterCard = '<meta name="twitter:card" content="summary_large_image" >';
|
2017-11-09 23:30:13 +01:00
|
|
|
return new Handlebars.SafeString(`${basicTwitterTags} ${twitterCard}`);
|
2017-09-17 02:50:22 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
ifConditional (varOne, operator, varTwo, options) {
|
|
|
|
switch (operator) {
|
|
|
|
case '===':
|
|
|
|
return (varOne === varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '!==':
|
|
|
|
return (varOne !== varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '<':
|
|
|
|
return (varOne < varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '<=':
|
|
|
|
return (varOne <= varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '>':
|
|
|
|
return (varOne > varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '>=':
|
|
|
|
return (varOne >= varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '&&':
|
|
|
|
return (varOne && varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case '||':
|
|
|
|
return (varOne || varTwo) ? options.fn(this) : options.inverse(this);
|
|
|
|
case 'mod3':
|
|
|
|
return ((parseInt(varOne) % 3) === 0) ? options.fn(this) : options.inverse(this);
|
|
|
|
default:
|
|
|
|
return options.inverse(this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|