Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate pagination from empty collection #41

Closed
yamavol opened this issue Feb 22, 2019 · 2 comments
Closed

Generate pagination from empty collection #41

yamavol opened this issue Feb 22, 2019 · 2 comments

Comments

@yamavol
Copy link

yamavol commented Feb 22, 2019

Thank you for writing this great plugin. It is one of my core components in my build chain for a while.

Do you think it is worth to generate a pagination even when the collection is empty? Currently, this plugin does not add any new pages when there are no files inside the specified collection.

This is useful when the collection is generated dynamically. Suppose 3 collections (a, b, c) are prepared in advance, then we scan through all files and add them into one of them, We expect this plugin to generate 'a/page/1.html', 'b/page/1.html', 'c/page/1.html'. This plugin currently does not generate pages for empty collection, so the file existence becomes inconsistent.

I am currently modifying(add) your code like below in my project. I'm not sure about the potential demerits, but it would be nice if this feature is officially supported.

...
if (collection.length == 0 && pageOptions.emptyPage) {
  var params = {
    name: '0',
    index: 0,
    num: 1
  }

  // Generate the page data.
  var page = extend(pageOptions.pageMetadata, {
    template: pageOptions.emptyPage.template,
    layout: pageOptions.emptyPage.layout,
    contents: pageOptions.emptyPage.pageContents || Buffer.from(''),
    path: interpolate(pageOptions.path, params),
  })

  if (!pageOptions.noPageOne) {
    files[page.path] = page
  }

  if (pageOptions.first) {
    // Extend the "first page" over the top of "page one".
    page = extend(page, {
      path: interpolate(pageOptions.first, params)
    })

    files[page.path] = page
  }
}
...

In addition, solving issue #25 makes this feature even more useful, I guess.

@blakeembrey
Copy link
Owner

@yamavol Happy to accept a PR supporting "empty/missing collections". I expect it should be a flag, when enabled, would render the first page with no entries.

@blakeembrey
Copy link
Owner

Added support in 3c94337. You can use empty: true or empty: fileObject if you are using groupBy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants