From bfd3971bd540b84d335cd131d17b46983410a66e Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 29 Oct 2018 14:47:47 -0400 Subject: [PATCH] alter createCanonicalLink to take an object parameter --- client/src/containers/AssetInfo/view.jsx | 24 ++++++++++++++---------- client/src/containers/SEO/view.jsx | 7 ++++++- client/src/utils/createCanonicalLink.js | 24 ++++++++++++------------ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/client/src/containers/AssetInfo/view.jsx b/client/src/containers/AssetInfo/view.jsx index 63d16e10..14d514a0 100644 --- a/client/src/containers/AssetInfo/view.jsx +++ b/client/src/containers/AssetInfo/view.jsx @@ -6,19 +6,23 @@ import Row from '@components/Row'; import SpaceBetween from '@components/SpaceBetween'; import AssetShareButtons from '@components/AssetShareButtons'; import ClickToCopy from '@components/ClickToCopy'; +import createCanonicalLink from '../../utils/createCanonicalLink'; class AssetInfo extends React.Component { render () { - const { - asset: { - shortId, - claimData : { - channelName, certificateId, description, name, claimId, fileExt, contentType, thumbnail, host - }, - claimViews, - } - } = this.props; + const { asset } = this.props; + const { shortId, claimData: { channelName, channelShortId, certificateId, description, name, claimId, fileExt, contentType, thumbnail, host } } = asset; + const assetCanonicalUrl = createCanonicalLink({asset}); + + let channelCanonicalUrl; + if (channelName) { + const channel = { + name: channelName, + shortId: channelShortId, + }; + channelCanonicalUrl = createCanonicalLink({channel}); + } return (
{channelName && ( @@ -29,7 +33,7 @@ class AssetInfo extends React.Component { } content={ - {channelName} + {channelName} } /> diff --git a/client/src/containers/SEO/view.jsx b/client/src/containers/SEO/view.jsx index 05f9d83f..869976ba 100644 --- a/client/src/containers/SEO/view.jsx +++ b/client/src/containers/SEO/view.jsx @@ -21,7 +21,12 @@ class SEO extends React.Component { asset, channel, }); - const canonicalLink = createCanonicalLink(asset, channel, pageUri); + const canonicalLink = createCanonicalLink({ + asset, + channel, + page: pageUri, + absolute: true, + }); // render results return ( { - return `${host}/${page}`; +const createBasicCanonicalLink = (absolute, page) => { + return `${absolute ? host : ''}/${page}`; }; -const createAssetCanonicalLink = (asset) => { +const createAssetCanonicalLink = (absolute, asset) => { let channelName, channelShortId, name, claimId; if (asset.claimData) { ({ channelName, channelShortId, name, claimId } = asset.claimData); } if (channelName) { - return `${host}/${channelName}:${channelShortId}/${name}`; + return `${absolute ? host : ''}/${channelName}:${channelShortId}/${name}`; } - return `${host}/${claimId}/${name}`; + return `${absolute ? host : ''}/${claimId}/${name}`; }; -const createChannelCanonicalLink = (channel) => { - const { name, longId } = channel; - return `${host}/${name}:${longId}`; +const createChannelCanonicalLink = (absolute, channel) => { + const { name, longId, shortId } = channel; + return `${absolute ? host : ''}/${name}:${shortId ? shortId : longId}`; }; -const createCanonicalLink = (asset, channel, page) => { +const createCanonicalLink = ({asset, channel, page, absolute = false}) => { if (asset) { - return createAssetCanonicalLink(asset); + return createAssetCanonicalLink(absolute, asset); } if (channel) { - return createChannelCanonicalLink(channel); + return createChannelCanonicalLink(absolute, channel); } - return createBasicCanonicalLink(page); + return createBasicCanonicalLink(absolute, page); }; export default createCanonicalLink;