spee.ch/react/utils/canonicalLink.js

38 lines
940 B
JavaScript
Raw Normal View History

const { details: { host } } = require('../../config/siteConfig.js');
2018-02-23 20:00:46 +01:00
const createBasicCanonicalLink = (page) => {
2018-02-23 20:00:46 +01:00
if (!page) {
return `${host}`;
};
return `${host}/${page}`;
};
const createAssetCanonicalLink = (asset) => {
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 `${host}/${channelName}:${certificateId}/${name}`;
};
return `${host}/${claimId}/${name}`;
};
const createChannelCanonicalLink = (channel) => {
2018-02-23 20:00:46 +01:00
const { name, longId } = channel;
return `${host}/${name}:${longId}`;
};
export const createCanonicalLink = (asset, channel, page) => {
if (asset) {
return createAssetCanonicalLink(asset);
}
if (channel) {
return createChannelCanonicalLink(channel);
}
if (page) {
return createBasicCanonicalLink(page);
}
return createBasicCanonicalLink();
};