diff --git a/helpers/renderFullPage.js b/helpers/renderFullPage.js index 4c5089ad..4786da58 100644 --- a/helpers/renderFullPage.js +++ b/helpers/renderFullPage.js @@ -9,6 +9,7 @@ module.exports = (helmet, html, preloadedState) => { ${helmet.title.toString()} + ${helmet.meta.toString()} ${helmet.link.toString()} diff --git a/react/components/OpenGraphTags/index.jsx b/react/components/OpenGraphTags/index.jsx new file mode 100644 index 00000000..0af0073c --- /dev/null +++ b/react/components/OpenGraphTags/index.jsx @@ -0,0 +1,21 @@ +import { connect } from 'react-redux'; +import View from './view'; + +const mapStateToProps = ({ show }) => { + // select request info + const requestId = show.request.id; + // select asset info + let asset; + const request = show.requestList[requestId] || null; + const assetList = show.assetList; + if (request && assetList) { + const assetKey = request.key; // note: just store this in the request + asset = assetList[assetKey] || null; + }; + // return props + return { + asset, + }; +}; + +export default connect(mapStateToProps, null)(View); diff --git a/react/components/OpenGraphTags/view.jsx b/react/components/OpenGraphTags/view.jsx new file mode 100644 index 00000000..85a53cfe --- /dev/null +++ b/react/components/OpenGraphTags/view.jsx @@ -0,0 +1,83 @@ +import React from 'react'; +import Helmet from 'react-helmet'; + +const { site: { title, host }, claim: { defaultThumbnail, defaultDescription } } = require('../../../config/speechConfig.js'); + +const determineOgThumbnailContentType = (thumbnail) => { + if (thumbnail) { + const fileExt = thumbnail.substring(thumbnail.lastIndexOf('.')); + switch (fileExt) { + 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'; + } + } + return ''; +}; + +class OpenGraphTags extends React.Component { + render () { + const { claimData } = this.props.asset; + const { contentType } = claimData; + const embedUrl = `${host}/${claimData.claimId}/${claimData.name}`; + const showUrl = `${host}/${claimData.claimId}/${claimData.name}`; + const source = `${host}/${claimData.claimId}/${claimData.name}.${claimData.fileExt}`; + const ogTitle = claimData.title || claimData.name; + const ogDescription = claimData.description || defaultDescription; + const ogThumbnailContentType = determineOgThumbnailContentType(claimData.thumbnail); + const ogThumbnail = claimData.thumbnail || defaultThumbnail; + return ( +