Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Posts pagination #4

Closed
kbariotis opened this issue Jul 16, 2017 · 4 comments
Closed

Posts pagination #4

kbariotis opened this issue Jul 16, 2017 · 4 comments
Assignees

Comments

@kbariotis
Copy link

Is pagination for posts on your plans? It would be a great feature to have.

@elmasse
Copy link
Owner

elmasse commented Jul 16, 2017

@kbariotis yes it is. I have to do some testing, not quite sure yet how that will work but it'll be addressed soon.

@elmasse elmasse self-assigned this Jul 16, 2017
@kbariotis
Copy link
Author

Yes its tricky but super useful.

Things to consider:

  • Should it generate a different page for each posts batch under the blog/page/pageNo path? Phenomic took another approach with the Immutable pagination.
  • The path should be configurable so after one migrates from another blog, she should be able to keep her old links
  • Pagination should also take in consideration tags/categories pages. (tags/tagName/page/pageNo)

Let me know what you think and if I could help you on that.

@elmasse
Copy link
Owner

elmasse commented Jul 18, 2017

@kbariotis

Thanks for all that information. I'll check Phenomic solution in deep, seems pretty interesting.
Regarding configuration that is still a subject I will love to explore more. Right now the need to configure next thru nextein is solved by the config wrapper. I'd like to explore how can I keep the door open for next config + internal configuration and allow a similar mechanism for nextein.

But this is topic for pagination. I will try to find out some time later this week to play with some possible solutions taking aside configuration by now. I'm more than open to suggestions, so if you have the time and want to contribute I'd love to evaluate alternatives!

Thanks a lot!
Max

@knoebelja
Copy link
Contributor

Here is how I implemented pagination. It may give you inspiration for something more complex.

Wrap your page with both withPost and withPosts to get your current post and all other posts as well. Then find the index of your current post:

  const currentData = post.data;
  const currentIndex = posts.findIndex(post => currentData.url === post.data.url);

Import a component like such:

const PagionationLink = ({ direction, post }) => {
  if (post) {
    return (
      <div>
        <div>{direction}</div>
        <div>
          <NexteinLink {...post}>
            <a>{post.data.title}</a>
          </NexteinLink>
        </div>
      </div>
    );
  } else {
    return <div />;
  }
};

Then pass props to it like such:

<PaginationLink direction="Previous" post={posts[currentIndex - 1]} />
<PaginationLink direction="Next" post={posts[currentIndex + 1]} />

If there's no post at the previous or next index, it returns blank. Otherwise it renders.

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

No branches or pull requests

3 participants