2018-10-29 21:35:57 +01:00
|
|
|
const createBasicCanonicalLink = (page) => {
|
|
|
|
return `/${page}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const createAssetCanonicalLink = (asset) => {
|
2018-11-02 18:27:18 +01:00
|
|
|
const { channelName, channelShortId, name, claimId, shortId } = asset;
|
|
|
|
return channelName ? `/${channelName}:${channelShortId}/${name}` : `/${shortId || claimId}/${name}`;
|
2018-10-29 21:35:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|