generator.js 607 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const pagination = require('hexo-pagination');
  3. const { sort } = require('timsort');
  4. module.exports = function(locals) {
  5. const config = this.config;
  6. const posts = locals.posts.sort(config.index_generator.order_by);
  7. sort(posts.data, (a, b) => (b.sticky || 0) - (a.sticky || 0));
  8. const paginationDir = config.pagination_dir || 'page';
  9. const path = config.index_generator.path || '';
  10. return pagination(path, posts, {
  11. perPage: config.index_generator.per_page,
  12. layout: ['index', 'archive'],
  13. format: paginationDir + '/%d/',
  14. data: {
  15. __index: true
  16. }
  17. });
  18. };