alter createCanonicalLink to take an object parameter
This commit is contained in:
parent
46675107cd
commit
bfd3971bd5
3 changed files with 32 additions and 23 deletions
|
@ -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 (
|
||||
<div>
|
||||
{channelName && (
|
||||
|
@ -29,7 +33,7 @@ class AssetInfo extends React.Component {
|
|||
}
|
||||
content={
|
||||
<span className='text'>
|
||||
<Link to={`/${channelName}:${certificateId}`}>{channelName}</Link>
|
||||
<Link to={channelCanonicalUrl}>{channelName}</Link>
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
|
|
|
@ -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 (
|
||||
<Helmet
|
||||
|
|
|
@ -6,34 +6,34 @@ const {
|
|||
},
|
||||
} = siteConfig;
|
||||
|
||||
const createBasicCanonicalLink = (page) => {
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue