-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pagination): enabled pagination logic
but there are currently no links between pages
- Loading branch information
Showing
2 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,54 @@ | ||
const path = require('path'); | ||
|
||
module.exports = ({graphql, actions}) => { | ||
function createMeetingPages(meetings, createPage) { | ||
meetings.forEach(({node}) => { | ||
if (!node.fields || !node.fields.slug) return; | ||
|
||
createPage({ | ||
path: node.fields.slug, | ||
component: path.resolve('./src/templates/meeting.js'), | ||
context: {slug: node.fields.slug} | ||
}); | ||
}); | ||
} | ||
|
||
function createArchiveListPage(meetings, createPage) { | ||
const meetingsPerPage = 6; | ||
const totalPages = Math.ceil(meetings.length / meetingsPerPage); | ||
|
||
Array.from({length: totalPages}).forEach((_, index) => { | ||
createPage({ | ||
path: 0 === index ? '/archive' : `/archive/page-${index + 1}`, | ||
component: path.resolve('./src/templates/archive.js'), | ||
context: { | ||
limit: meetingsPerPage, | ||
skip: index * meetingsPerPage, | ||
totalPages, | ||
currentPage: index + 1 | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = async ({graphql, actions}) => { | ||
const {createPage} = actions; | ||
|
||
return graphql(` | ||
{ | ||
allMarkdownRemark { | ||
edges { | ||
node { | ||
fields { | ||
slug | ||
} | ||
const result = await graphql(` | ||
{ | ||
allMarkdownRemark { | ||
edges { | ||
node { | ||
fields { | ||
slug | ||
} | ||
} | ||
} | ||
} | ||
`).then(result => { | ||
result.data.allMarkdownRemark.edges.forEach(({node}) => { | ||
if (!node.fields || !node.fields.slug) return; | ||
|
||
createPage({ | ||
path: node.fields.slug, | ||
component: path.resolve('./src/templates/meeting.js'), | ||
context: {slug: node.fields.slug} | ||
}); | ||
}); | ||
}); | ||
} | ||
`); | ||
|
||
const meetings = result.data.allMarkdownRemark.edges; | ||
|
||
createMeetingPages(meetings, createPage); | ||
createArchiveListPage(meetings, createPage); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters