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

filter out parent page from ChildrenQuery response #332

Closed
1 of 5 tasks
thescientist13 opened this issue Apr 18, 2020 · 1 comment · Fixed by #388
Closed
1 of 5 tasks

filter out parent page from ChildrenQuery response #332

thescientist13 opened this issue Apr 18, 2020 · 1 comment · Fixed by #388
Assignees
Labels
breaking Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) v0.8.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Apr 18, 2020

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

Right now ChildrenQuery is returning the index.md as part of the array of pages returned, which is effectively the parent route. I think in this case, it doesn't make sense to return the parent if you are asking for the children, or else to render the children as a list, you'll have to exclude the parent, e.g. ${parent}/index.md

So effectively the resolver should just filter out index.md then.

Details

Given a structure like this

pages/
  blog/
    first-post.md
    index.md
    second-post.md
    third-post.md

And render it like this

render() {
  return html`
    <ul>
      ${posts.map((post) => {
        return html`
          <li>
            <a href="${post.link}" title="Click to read my ${post.title} blog post">${post.title}</a>
          </li>
        `;
       })}
     </ul>
  `
}

You'll have to something like this in your component

class BlogPostsTemplate extends LitElement {
  ...
  
  async connectedCallback() {
    super.connectedCallback();
    const response = await client.query({
      query: ChildrenQuery,
      variables: {
        parent: 'blog'
      }
    });

    this.posts = response.data.children.filter(post => {
      return post.filePath.indexOf('/blog/index') < 0;
    });
  }

Or else you'll have a list like this, when you probably only want the posts themselves

  1. First Post
  2. Blog
  3. Second Post
  4. Third Post
@thescientist13 thescientist13 added enhancement Improve something existing (e.g. no docs, new APIs, etc) Content as Data labels Apr 18, 2020
@thescientist13 thescientist13 added this to the MVP milestone Apr 18, 2020
@thescientist13
Copy link
Member Author

thescientist13 commented Jul 12, 2020

Another case of where filtering this out would be nice. going to try and work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) v0.8.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant