diff --git a/helpers/handlebarsHelpers.js b/helpers/handlebarsHelpers.js deleted file mode 100644 index 5e857070..00000000 --- a/helpers/handlebarsHelpers.js +++ /dev/null @@ -1,113 +0,0 @@ -const Handlebars = require('handlebars'); -const { site, claim: claimDefaults } = require('../config/speechConfig.js'); - -function determineOgTitle (storedTitle, defaultTitle) { - return ifEmptyReturnOther(storedTitle, defaultTitle); -}; - -function determineOgDescription (storedDescription, defaultDescription) { - const length = 200; - let description = ifEmptyReturnOther(storedDescription, defaultDescription); - if (description.length >= length) { - description = `${description.substring(0, length)}...`; - }; - return description; -}; - -function ifEmptyReturnOther (value, replacement) { - if (value === '') { - return replacement; - } - return value; -} - -function determineContentTypeFromFileExtension (fileExtension) { - switch (fileExtension) { - case 'jpeg': - case 'jpg': - return 'image/jpeg'; - case 'png': - return 'image/png'; - case 'gif': - return 'image/gif'; - case 'mp4': - return 'video/mp4'; - default: - return 'image/jpeg'; - } -}; - -function determineOgThumbnailContentType (thumbnail) { - if (thumbnail) { - if (thumbnail.lastIndexOf('.') !== -1) { - return determineContentTypeFromFileExtension(thumbnail.substring(thumbnail.lastIndexOf('.'))); - } - } - return ''; -} - -function createOpenGraphDataFromClaim (claim, defaultTitle, defaultDescription) { - let openGraphData = {}; - openGraphData['embedUrl'] = `${site.host}/${claim.claimId}/${claim.name}`; - openGraphData['showUrl'] = `${site.host}/${claim.claimId}/${claim.name}`; - openGraphData['source'] = `${site.host}/${claim.claimId}/${claim.name}.${claim.fileExt}`; - openGraphData['directFileUrl'] = `${site.host}/${claim.claimId}/${claim.name}.${claim.fileExt}`; - openGraphData['ogTitle'] = determineOgTitle(claim.title, defaultTitle); - openGraphData['ogDescription'] = determineOgDescription(claim.description, defaultDescription); - openGraphData['ogThumbnailContentType'] = determineOgThumbnailContentType(claim.thumbnail); - return openGraphData; -}; - -module.exports = { - placeCommonHeaderTags () { - const headerBoilerplate = `${site.title}`; - return new Handlebars.SafeString(headerBoilerplate); - }, - addOpenGraph (claim) { - const { ogTitle, ogDescription, showUrl, source, ogThumbnailContentType } = createOpenGraphDataFromClaim(claim, claimDefaults.defaultTitle, claimDefaults.defaultDescription); - const thumbnail = claim.thumbnail; - const contentType = claim.contentType; - const ogTitleTag = ``; - const ogUrlTag = ``; - const ogSiteNameTag = ``; - const ogDescriptionTag = ``; - const ogImageWidthTag = ''; - const ogImageHeightTag = ''; - const basicTags = `${ogTitleTag} ${ogUrlTag} ${ogSiteNameTag} ${ogDescriptionTag} ${ogImageWidthTag} ${ogImageHeightTag}`; - let ogImageTag = ``; - let ogImageTypeTag = ``; - let ogTypeTag = ``; - if (contentType === 'video/mp4') { - const ogVideoTag = ``; - const ogVideoSecureUrlTag = ``; - const ogVideoTypeTag = ``; - ogImageTag = ``; - ogImageTypeTag = ``; - ogTypeTag = ``; - return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag} ${ogVideoTag} ${ogVideoSecureUrlTag} ${ogVideoTypeTag}`); - } else { - if (contentType === 'image/gif') { - ogTypeTag = ``; - }; - return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag}`); - } - }, - addTwitterCard (claim) { - const { embedUrl, directFileUrl } = createOpenGraphDataFromClaim(claim, claimDefaults.defaultTitle, claimDefaults.defaultDescription); - const basicTwitterTags = ``; - const contentType = claim.contentType; - if (contentType === 'video/mp4') { - const twitterName = ''; - const twitterPlayer = ``; - const twitterPlayerWidth = ''; - const twitterTextPlayerWidth = ''; - const twitterPlayerHeight = ''; - const twitterPlayerStream = ``; - const twitterPlayerStreamContentType = ''; - return new Handlebars.SafeString(`${basicTwitterTags} ${twitterName} ${twitterPlayer} ${twitterPlayerWidth} ${twitterTextPlayerWidth} ${twitterPlayerHeight} ${twitterPlayerStream} ${twitterPlayerStreamContentType}`); - } else { - const twitterCard = ''; - return new Handlebars.SafeString(`${basicTwitterTags} ${twitterCard}`); - } - }, -}; diff --git a/routes/fallback-routes.js b/routes/fallback-routes.js index 96d3df44..9034b4a8 100644 --- a/routes/fallback-routes.js +++ b/routes/fallback-routes.js @@ -1,7 +1,9 @@ +const handlePageRender = require('../helpers/handlePageRender.jsx'); + module.exports = app => { // a catch-all route if someone visits a page that does not exist - app.use('*', ({ originalUrl, ip }, res) => { + app.use('*', (req, res) => { // send response - res.status(404).render('404'); + handlePageRender(req, res); }); }; diff --git a/server.js b/server.js index 0a3d8621..9303e671 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,6 @@ const express = require('express'); const bodyParser = require('body-parser'); const expressHandlebars = require('express-handlebars'); const Handlebars = require('handlebars'); -const handlebarsHelpers = require('./helpers/handlebarsHelpers.js'); const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js'); const config = require('./config/speechConfig.js'); const logger = require('winston'); @@ -53,9 +52,8 @@ app.use(passport.session()); // configure handlebars & register it with express app const hbs = expressHandlebars.create({ - defaultLayout: 'main', // sets the default layout + defaultLayout: 'embed', // sets the default layout handlebars : Handlebars, // includes basic handlebars for access to that library - helpers : handlebarsHelpers, // custom defined helpers }); app.engine('handlebars', hbs.engine); app.set('view engine', 'handlebars'); diff --git a/views/404.handlebars b/views/404.handlebars deleted file mode 100644 index 9cc0a1c4..00000000 --- a/views/404.handlebars +++ /dev/null @@ -1,4 +0,0 @@ -
-

404: Not Found

-

That page does not exist. Return home.

-
diff --git a/views/index.handlebars b/views/index.handlebars deleted file mode 100644 index 075fe851..00000000 --- a/views/index.handlebars +++ /dev/null @@ -1,10 +0,0 @@ -
-
-
-

loading...

- {{> progressBar}} -
-
-
- - diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars deleted file mode 100644 index 18122a33..00000000 --- a/views/layouts/main.handlebars +++ /dev/null @@ -1,19 +0,0 @@ - - - - {{ placeCommonHeaderTags }} - - - - - - - - - - - - - {{{ body }}} - -