Skip to content

Commit

Permalink
Merge 7ccd132 into 0045d3e
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 5, 2020
2 parents 0045d3e + 7ccd132 commit 71aef0b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/pagination.js
Expand Up @@ -6,23 +6,26 @@ function pagination(base, posts, options = {}) {
if (typeof base !== 'string') throw new TypeError('base must be a string!');
if (!posts) throw new TypeError('posts is required!');

if (base && base[base.length - 1] !== '/') base += '/';
if (base && !base.endsWith('/')) base += '/';

const { length } = posts;

const { format: _format, layout, data, perPage } = Object.assign({
format: 'page/%d/',
layout: ['archive', 'index'],
data: {},
perPage: 10
}, options);

const length = posts.length;
const perPage = Object.prototype.hasOwnProperty.call(options, 'perPage') ? +options.perPage : 10;
const total = perPage ? Math.ceil(length / perPage) : 1;
const _format = options.format || 'page/%d/';
const layout = options.layout || ['archive', 'index'];
const data = options.data || {};
const result = [];
const urlCache = {};
const urlCache = new Map();

function formatURL(i) {
if (urlCache[i]) return urlCache[i];
if (urlCache.has(i)) return urlCache.get(i);

let url = base;
if (i > 1) url += format(_format, i);
urlCache[i] = url;
const url = i > 1 ? base + format(_format, i) : base;
urlCache.set(i, url);

return url;
}
Expand Down

0 comments on commit 71aef0b

Please sign in to comment.