c8119eee1f
refs #6982
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
var schema = require('../schema').checks,
|
|
utils = require('../../utils');
|
|
|
|
// 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)) {
|
|
return utils.url.urlFor('post', {post: data, secure: data.secure}, absolute);
|
|
}
|
|
|
|
if (schema.isTag(data)) {
|
|
return utils.url.urlFor('tag', {tag: data, secure: data.secure}, absolute);
|
|
}
|
|
|
|
if (schema.isUser(data)) {
|
|
return utils.url.urlFor('author', {author: data, secure: data.secure}, absolute);
|
|
}
|
|
|
|
if (schema.isNav(data)) {
|
|
return utils.url.urlFor('nav', {nav: data, secure: data.secure}, absolute);
|
|
}
|
|
|
|
// sanitize any trailing `/amp` in the url
|
|
return sanitizeAmpUrl(utils.url.urlFor(data, {}, absolute));
|
|
}
|
|
|
|
module.exports = getUrl;
|