From 2a6238e850fc4ef297795aee444e61b0c2ea0928 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Sat, 25 Jul 2020 14:54:41 -0400 Subject: [PATCH] filter out index page from children query (#388) * filter out index page from children query * adjust logic for filter parent pages * remove index filter --- packages/cli/src/data/schema/graph.js | 2 +- .../src/templates/blog-template.js | 4 +-- .../cli/test/unit/data/schema/graph.spec.js | 33 ++++++++----------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/packages/cli/src/data/schema/graph.js b/packages/cli/src/data/schema/graph.js index 1c1c51a27..f5a74b73d 100644 --- a/packages/cli/src/data/schema/graph.js +++ b/packages/cli/src/data/schema/graph.js @@ -129,7 +129,7 @@ const getChildrenFromParentRoute = async (root, query, context) => { const { label } = getDeriveMetaFromRoute(route); const root = route.split('/')[1]; - if (root.indexOf(parent) >= 0) { + if (root.indexOf(parent) >= 0 && mdFile !== `./${parent}/index.md`) { const id = page.label; pages.push({ diff --git a/packages/cli/test/cases/build.data.graph/src/templates/blog-template.js b/packages/cli/test/cases/build.data.graph/src/templates/blog-template.js index 110338c66..5a0e50b1f 100644 --- a/packages/cli/test/cases/build.data.graph/src/templates/blog-template.js +++ b/packages/cli/test/cases/build.data.graph/src/templates/blog-template.js @@ -27,9 +27,7 @@ class BlogTemplate extends LitElement { } }); - this.posts = response.data.children.filter(post => { - return post.filePath.indexOf('/blog/index') < 0; - }); + this.posts = response.data.children; } /* eslint-disable indent */ diff --git a/packages/cli/test/unit/data/schema/graph.spec.js b/packages/cli/test/unit/data/schema/graph.spec.js index 3448ec8a2..c33792d65 100644 --- a/packages/cli/test/unit/data/schema/graph.spec.js +++ b/packages/cli/test/unit/data/schema/graph.spec.js @@ -39,25 +39,22 @@ describe('Unit Test: Data', function() { }); it('should have 8 children', function() { - expect(children.length).to.equal(8); + expect(children.length).to.equal(7); }); it('should have the expected value for id for each child', function() { expect(children[0].id).to.equal('css-components'); expect(children[1].id).to.equal('deploy'); expect(children[2].id).to.equal('create-content'); - expect(children[3].id).to.equal('getting-started'); - expect(children[4].id).to.equal('concepts'); - expect(children[5].id).to.equal('next'); - expect(children[6].id).to.equal('project-setup'); - expect(children[7].id).to.equal('start'); + expect(children[3].id).to.equal('concepts'); + expect(children[4].id).to.equal('next'); + expect(children[5].id).to.equal('project-setup'); + expect(children[6].id).to.equal('start'); }); it('should have the expected filePath for each child', function() { children.forEach(function(child) { - const path = child.fileName === 'index' ? '' : child.fileName; - - expect(child.link).to.equal(`/getting-started/${path}`); + expect(child.link).to.equal(`/getting-started/${child.fileName}`); }); }); @@ -65,11 +62,10 @@ describe('Unit Test: Data', function() { expect(children[0].fileName).to.equal('branding'); expect(children[1].fileName).to.equal('build-and-deploy'); expect(children[2].fileName).to.equal('creating-content'); - expect(children[3].fileName).to.equal('index'); - expect(children[4].fileName).to.equal('key-concepts'); - expect(children[5].fileName).to.equal('next-steps'); - expect(children[6].fileName).to.equal('project-setup'); - expect(children[7].fileName).to.equal('quick-start'); + expect(children[3].fileName).to.equal('key-concepts'); + expect(children[4].fileName).to.equal('next-steps'); + expect(children[5].fileName).to.equal('project-setup'); + expect(children[6].fileName).to.equal('quick-start'); }); it('should have the expected link for each child', function() { @@ -88,11 +84,10 @@ describe('Unit Test: Data', function() { expect(children[0].title).to.equal('Styles and Web Components'); expect(children[1].title).to.equal('Build and Deploy'); expect(children[2].title).to.equal('Creating Content'); - expect(children[3].title).to.equal('Getting Started'); - expect(children[4].title).to.equal('Key Concepts'); - expect(children[5].title).to.equal('Next Steps'); - expect(children[6].title).to.equal('Project Setup'); - expect(children[7].title).to.equal('Quick Start'); + expect(children[3].title).to.equal('Key Concepts'); + expect(children[4].title).to.equal('Next Steps'); + expect(children[5].title).to.equal('Project Setup'); + expect(children[6].title).to.equal('Quick Start'); }); it('should have expected custom front matter data if it is set', function() {