spee.ch/react/utils/canonicalLink.js

30 lines
857 B
JavaScript
Raw Normal View History

const createBasicCanonicalLink = (page, siteHost) => {
return `${siteHost}/${page}`;
2018-02-23 20:00:46 +01:00
};
const createAssetCanonicalLink = (asset, siteHost) => {
2018-02-23 20:00:46 +01:00
let channelName, certificateId, name, claimId;
if (asset.claimData) {
({ channelName, certificateId, name, claimId } = asset.claimData);
};
if (channelName) {
return `${siteHost}/${channelName}:${certificateId}/${name}`;
2018-02-23 20:00:46 +01:00
};
return `${siteHost}/${claimId}/${name}`;
2018-02-23 20:00:46 +01:00
};
const createChannelCanonicalLink = (channel, siteHost) => {
2018-02-23 20:00:46 +01:00
const { name, longId } = channel;
return `${siteHost}/${name}:${longId}`;
2018-02-23 20:00:46 +01:00
};
export const createCanonicalLink = (asset, channel, page, siteHost) => {
if (asset) {
return createAssetCanonicalLink(asset, siteHost);
}
if (channel) {
return createChannelCanonicalLink(channel, siteHost);
}
return createBasicCanonicalLink(page, siteHost);
};