mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 04:27:04 +02:00
feat(plugin-blog): allow 'ALL'
as postsPerPage
option value (#5354)
* 'ALL' option Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Guard against zero posts Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Remove redundant code Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
parent
ee6882650e
commit
7d0272fe4d
5 changed files with 17 additions and 11 deletions
|
@ -103,7 +103,12 @@ export default function pluginContentBlog(
|
|||
|
||||
// Fetches blog contents and returns metadata for the necessary routes.
|
||||
async loadContent() {
|
||||
const {postsPerPage, routeBasePath} = options;
|
||||
const {
|
||||
postsPerPage: postsPerPageOption,
|
||||
routeBasePath,
|
||||
blogDescription,
|
||||
blogTitle,
|
||||
} = options;
|
||||
|
||||
const blogPosts: BlogPost[] = await generateBlogPosts(
|
||||
contentPaths,
|
||||
|
@ -143,6 +148,8 @@ export default function pluginContentBlog(
|
|||
// Blog pagination routes.
|
||||
// Example: `/blog`, `/blog/page/1`, `/blog/page/2`
|
||||
const totalCount = blogPosts.length;
|
||||
const postsPerPage =
|
||||
postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
|
||||
const numberOfPages = Math.ceil(totalCount / postsPerPage);
|
||||
const {
|
||||
siteConfig: {baseUrl = ''},
|
||||
|
@ -170,8 +177,8 @@ export default function pluginContentBlog(
|
|||
page < numberOfPages - 1
|
||||
? blogPaginationPermalink(page + 1)
|
||||
: null,
|
||||
blogDescription: options.blogDescription,
|
||||
blogTitle: options.blogTitle,
|
||||
blogDescription,
|
||||
blogTitle,
|
||||
},
|
||||
items: blogPosts
|
||||
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue