mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
1bd8c18a16
* moved url-utils from server to shared * updated imports of url-utils
21 lines
547 B
JavaScript
21 lines
547 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;
|
|
}
|
|
|
|
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;
|