move createCanonicalLink to shared utils

This commit is contained in:
Travis Eden 2018-10-29 16:35:57 -04:00
parent bfd3971bd5
commit c912226ae9
2 changed files with 31 additions and 39 deletions

View file

@ -1,39 +0,0 @@
import siteConfig from '@config/siteConfig.json';
const {
details: {
host,
},
} = siteConfig;
const createBasicCanonicalLink = (absolute, page) => {
return `${absolute ? host : ''}/${page}`;
};
const createAssetCanonicalLink = (absolute, asset) => {
let channelName, channelShortId, name, claimId;
if (asset.claimData) {
({ channelName, channelShortId, name, claimId } = asset.claimData);
}
if (channelName) {
return `${absolute ? host : ''}/${channelName}:${channelShortId}/${name}`;
}
return `${absolute ? host : ''}/${claimId}/${name}`;
};
const createChannelCanonicalLink = (absolute, channel) => {
const { name, longId, shortId } = channel;
return `${absolute ? host : ''}/${name}:${shortId ? shortId : longId}`;
};
const createCanonicalLink = ({asset, channel, page, absolute = false}) => {
if (asset) {
return createAssetCanonicalLink(absolute, asset);
}
if (channel) {
return createChannelCanonicalLink(absolute, channel);
}
return createBasicCanonicalLink(absolute, page);
};
export default createCanonicalLink;

View file

@ -0,0 +1,31 @@
const createBasicCanonicalLink = (page) => {
return `/${page}`;
};
const createAssetCanonicalLink = (asset) => {
let channelName, channelShortId, name, claimId;
if (asset.claimData) {
({ channelName, channelShortId, name, claimId } = asset.claimData);
}
if (channelName) {
return `/${channelName}:${channelShortId}/${name}`;
}
return `/${claimId}/${name}`;
};
const createChannelCanonicalLink = (channel) => {
const { name, shortId } = channel;
return `/${name}:${shortId}`;
};
const createCanonicalLink = ({asset, channel, page}) => {
if (asset) {
return createAssetCanonicalLink(asset);
}
if (channel) {
return createChannelCanonicalLink(channel);
}
return createBasicCanonicalLink(page);
};
module.exports = createCanonicalLink;