mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
19 lines
610 B
JavaScript
19 lines
610 B
JavaScript
|
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;
|