0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/server/data/meta/previous_url.js

19 lines
610 B
JavaScript
Raw Normal View History

var config = require('../../config'),
trimmedUrlpattern = /.+(?=\/page\/\d*\/)/;
function getPreviousUrl(data, absolute) {
var trimmedUrl, prev;
if (data.relativeUrl) {
trimmedUrl = data.relativeUrl.match(trimmedUrlpattern);
if (data.pagination && data.pagination.prev) {
prev = (data.pagination.prev > 1 ? '/page/' + data.pagination.prev + '/' : '/');
prev = (trimmedUrl) ? trimmedUrl + prev : prev;
return config.urlFor({relativeUrl: prev, secure: data.secure}, absolute);
}
}
return null;
}
module.exports = getPreviousUrl;