Skip to content

Commit

Permalink
Merge branch 'master' into getport
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist authored May 27, 2019
2 parents a8c5975 + 995711c commit 6191891
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/saber-plugin-query-posts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ injectAllPosts:

The limit of posts to show per page.

### firstPageOnly

- Type: `boolean`
- Default: `false`

Only generate the first page of posts.

### tagsMap

- Type: `{ [name: string]: string }`
Expand Down
3 changes: 2 additions & 1 deletion packages/saber-plugin-query-posts/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ exports.apply = (api, options = {}) => {
tagsMap: options.tagsMap,
categoriesMap: options.categoriesMap,
paginationOptions: {
perPage: options.perPage || 30
perPage: options.perPage || 30,
firstPageOnly: options.firstPageOnly
},
permalinks: Object.assign(
{
Expand Down
5 changes: 5 additions & 0 deletions packages/saber-plugin-query-posts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const slugify = require('slugo')

function paginate(arr, options) {
options = Object.assign({ perPage: 30 }, options)

if (options.firstPageOnly) {
return [arr.slice(0, options.perPage)]
}

const totalPages = Math.ceil(arr.length / options.perPage)
const result = []
for (let i = 0; i < totalPages; i++) {
Expand Down

0 comments on commit 6191891

Please sign in to comment.