0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/helpers/page_url.js
Hannah Wolfe 5f2c913fc1 Clean up paginated URL generation
refs #5091, #6612

- unify getNextUrl & getPrevUrl into getPaginatedUrl
- ensure that it can generate a prev, next or exact page no url
- ensure that it can figure out the base url
- use the same code from the page_url helper
- refactor the tests to ensure there's 100% coverage

Following on from #6612, this ensures that pagination always works regardless of whether the channel is default or custom
2016-03-20 22:35:00 +00:00

39 lines
1 KiB
JavaScript

// ### Page URL Helper
//
// *Usage example:*
// `{{page_url 2}}`
//
// Returns the URL for the page specified in the current object
// context.
//
// We use the name page_url to match the helper for consistency:
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var errors = require('../errors'),
i18n = require('../i18n'),
getPaginatedUrl = require('../data/meta/paginated_url'),
page_url,
pageUrl;
page_url = function (page, options) {
return getPaginatedUrl(page, options.data.root);
};
// ### Page URL Helper: DEPRECATED
//
// *Usage example:*
// `{{pageUrl 2}}`
//
// Returns the URL for the page specified in the current object
// context. This helper is deprecated and will be removed in future versions.
//
pageUrl = function (pageNum, options) {
errors.logWarn(i18n.t('warnings.helpers.page_url.isDeprecated'));
/*jshint unused:false*/
var self = this;
return page_url.call(self, pageNum, options);
};
module.exports = page_url;
module.exports.deprecated = pageUrl;