Ghost/core/frontend/meta/canonical-url.js
Hannah Wolfe af4bfb8862
Changed meta filenames to correct casing
- purely for cleanliness!
- we use kebabcase by default
- tests should be kebab-case-file_spec.js (one day we want this to be .test.js)
2021-07-01 12:30:25 +01:00

25 lines
674 B
JavaScript

const _ = require('lodash');
const urlUtils = require('../../shared/url-utils');
const getUrl = require('./url');
function getCanonicalUrl(data) {
if ((_.includes(data.context, 'post') || _.includes(data.context, 'page'))
&& data.post && data.post.canonical_url) {
return data.post.canonical_url;
}
if (_.includes(data.context, 'tag') && data.tag && data.tag.canonical_url) {
return data.tag.canonical_url;
}
let url = urlUtils.urlJoin(urlUtils.urlFor('home', true), getUrl(data, false));
if (url.indexOf('/amp/')) {
url = url.replace(/\/amp\/$/i, '/');
}
return url;
}
module.exports = getCanonicalUrl;