mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
7b0d5d465b
closes #9675 - with dynamic routing we have introduced a breaking change, which we have overseen - Ghost does not return absolute urls, that's why the clients need to concat the blog url and the resource url - with 1.24.0 Ghost returned resource urls including the subdirectory - this caused trouble for e.g. zapier or the preview feature in the admin client - revert breaking change and ensure we only expose resource urls without subdirectory
27 lines
935 B
JavaScript
27 lines
935 B
JavaScript
var schema = require('../schema').checks,
|
|
urlService = require('../../services/url');
|
|
|
|
// This cleans the url from any `/amp` postfixes, so we'll never
|
|
// output a url with `/amp` in the end, except for the needed `amphtml`
|
|
// canonical link, which is rendered by `getAmpUrl`.
|
|
function sanitizeAmpUrl(url) {
|
|
if (url.indexOf('/amp/') !== -1) {
|
|
url = url.replace(/\/amp\/$/i, '/');
|
|
}
|
|
return url;
|
|
}
|
|
|
|
function getUrl(data, absolute) {
|
|
if (schema.isPost(data) || schema.isTag(data) || schema.isUser(data)) {
|
|
return urlService.getUrlByResourceId(data.id, {secure: data.secure, absolute: absolute, withSubdirectory: true});
|
|
}
|
|
|
|
if (schema.isNav(data)) {
|
|
return urlService.utils.urlFor('nav', {nav: data, secure: data.secure}, absolute);
|
|
}
|
|
|
|
// sanitize any trailing `/amp` in the url
|
|
return sanitizeAmpUrl(urlService.utils.urlFor(data, {}, absolute));
|
|
}
|
|
|
|
module.exports = getUrl;
|