move createCanonicalLink to shared utils
This commit is contained in:
parent
bfd3971bd5
commit
c912226ae9
2 changed files with 31 additions and 39 deletions
|
@ -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;
|
31
utils/createCanonicalLink.js
Normal file
31
utils/createCanonicalLink.js
Normal 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;
|
Loading…
Reference in a new issue