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

BlogRoll not using "count" property #844

Open
SalazarJosh opened this issue May 6, 2022 · 1 comment
Open

BlogRoll not using "count" property #844

SalazarJosh opened this issue May 6, 2022 · 1 comment

Comments

@SalazarJosh
Copy link

SalazarJosh commented May 6, 2022

Feature request

What is the expected behavior?
The BlogRoll has a count property that doesn't look to be implemented.

What is motivation or use case for adding/changing the behavior?
We should be able to use this count property to determine the number of blog posts to return. For example, I have a "latest from the blog" section that only shows the latest 3 blog posts.

How should this be implemented in your opinion?
The BlogRoll component should receive props and pass that to the BlogRollTemplate. That count can be used to slice the initial data or as part of the .map() function.

I'm doing the latter with a ternary operator to keep the count property optional.
{posts && posts.slice(0, (this.props.count != undefined ? this.props.count : this.props.data.length)).map(({ node: post }) => { ... }

Are you willing to work on this yourself?
yes

@maxcell
Copy link
Contributor

maxcell commented Aug 9, 2022

Interesting @SalazarJosh! So you'd like the count to be used to return back how many blog posts you'd want to get back? In my mind I was thinking this count would be only a read only to give back the total number of blog posts that we have. I think given that we're not using it, it might be be better for us to remove it.

We could use the count to be more like a "limit" since our page query ends up getting all blog posts in src/components/BlogRoll.js
https://github.com/netlify-templates/gatsby-starter-netlify-cms/blob/ca9d29cf97da7deb31827e9c8af666f281a72c7c/src/components/BlogRoll.js#L80-L84
So in here we'd want to add a new limit key and that way it only ever would show the latest 3 blog posts:

  query BlogRollQuery { 
    allMarkdownRemark( 
      sort: { order: DESC, fields: [frontmatter___date] } 
      filter: { frontmatter: { templateKey: { eq: "blog-post" } } },
      limit: 3
) { 

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

No branches or pull requests

2 participants