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 @@