Skip to content

Commit

Permalink
feat: add pagination to Markdown provider
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkdean committed Feb 22, 2017
1 parent a8e88ce commit 09618e7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dadi/lib/providers/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ MarkdownProvider.prototype.load = function load (requestUrl, done) {
const count = this.schema.datasource.count
const fields = this.schema.datasource.fields || []
const filter = this.schema.datasource.filter
const page = this.schema.datasource.page || 1

if (search) {
posts = _.where(posts, search)
Expand Down Expand Up @@ -90,8 +91,10 @@ MarkdownProvider.prototype.load = function load (requestUrl, done) {
})
}

if (count) {
posts = _.first(posts, count)
// Paginate if required
if (page && count) {
const offset = (page - 1) * count
posts = posts.slice(offset, offset + count)
}

if (fields && !_.isEmpty(fields)) {
Expand Down

0 comments on commit 09618e7

Please sign in to comment.