diff --git a/helpers/serveHelpers.js b/helpers/serveHelpers.js index 2d2aaed8..d6107d55 100644 --- a/helpers/serveHelpers.js +++ b/helpers/serveHelpers.js @@ -60,6 +60,14 @@ function checkLocalDbForClaims (name, shortUrl) { }); } +function createOpenGraphInfo ({ fileType, claimId, name, fileExt }) { + return { + type : fileType.substring(0, fileType.indexOf('/')), + showUrl: `https://spee.ch/${claimId}/${name}`, + source : `https://spee.ch/${claimId}/${name}${fileExt}`, + }; +} + module.exports = { serveFile ({ fileName, fileType, filePath }, res) { logger.info(`serving file ${fileName}`); @@ -86,11 +94,12 @@ module.exports = { res.status(200).sendFile(filePath, options); }, showFile (fileInfo, res) { - res.status(200).render('show', { layout: 'show', fileInfo }); + const openGraphInfo = createOpenGraphInfo(fileInfo); + res.status(200).render('show', { layout: 'show', fileInfo, openGraphInfo }); }, showFileLite (fileInfo, res) { - logger.debug('showing file lite'); - res.status(200).render('showLite', { layout: 'show', fileInfo }); + const openGraphInfo = createOpenGraphInfo(fileInfo); + res.status(200).render('showLite', { layout: 'show', fileInfo, openGraphInfo }); }, getClaimIdFromShortUrl (shortUrl, name) { return new Promise((resolve, reject) => { diff --git a/speech.js b/speech.js index c042e8ea..9ad2c025 100644 --- a/speech.js +++ b/speech.js @@ -48,6 +48,16 @@ const hbs = expressHandlebars.create({ ` ); }, + addOpenGraph (title, url, type, source, mimeType) { + return new Handlebars.SafeString( + ` + + + + + ` + ); + }, ifConditional (varOne, operator, varTwo, options) { switch (operator) { case '===': diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index dc6c235c..5de95460 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -7,7 +7,12 @@ Spee.ch - {{ twitterCard }} + + + + + + {{{ body }}} diff --git a/views/layouts/show.handlebars b/views/layouts/show.handlebars index a62a2781..21a9a2a7 100644 --- a/views/layouts/show.handlebars +++ b/views/layouts/show.handlebars @@ -8,16 +8,21 @@ - + {{!-- - + --}} + {{addOpenGraph fileInfo.name openGraphInfo.showUrl openGraphInfo.type openGraphInfo.source fileInfo.fileType }} {{{ body }}} {{ googleAnalytics }} - \ No newline at end of file + + + \ No newline at end of file diff --git a/views/partials/asset.handlebars b/views/partials/asset.handlebars index 9bf493a1..9e1568f3 100644 --- a/views/partials/asset.handlebars +++ b/views/partials/asset.handlebars @@ -1,6 +1,6 @@
- + {{#ifConditional fileInfo.fileType '===' 'video/mp4'}} - + {{addOpenGraph fileInfo.name links.showUrl 'video' links.source fileInfo.fileType }} {{else}} {{fileInfo.fileName}} + {{addOpenGraph fileInfo.name links.showUrl 'image' links.source fileInfo.fileType }} {{/ifConditional}}
\ No newline at end of file