mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
34fad7eaaf
refs #10593 - Added `canonical_url` field to post&pages resources in Admin & Content APIs - Support for canonical URL on metadata layer (used in {{ghost_head}} helper) - Made sure the new field is not accessible from API v0.1 - Added handling same domain relative and absolute URLs
21 lines
561 B
JavaScript
21 lines
561 B
JavaScript
const _ = require('lodash');
|
|
const urlService = require('../../services/url');
|
|
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 = urlService.utils.urlJoin(urlService.utils.urlFor('home', true), getUrl(data, false));
|
|
|
|
if (url.indexOf('/amp/')) {
|
|
url = url.replace(/\/amp\/$/i, '/');
|
|
}
|
|
|
|
return url;
|
|
}
|
|
|
|
module.exports = getCanonicalUrl;
|