Skip to content

Commit

Permalink
fix #455
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Dec 25, 2020
1 parent f3a4582 commit b2be2da
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/cli/src/lifecycles/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ module.exports = generateGraph = async (compilation) => {
* - pages/blog/some-post.{html,md} -> /blog/some-post/
*/
if (relativePagePath.lastIndexOf('/') > 0) {
route = `${route.replace('/index', '')}/`;
// https://github.com/ProjectEvergreen/greenwood/issues/455
route = label === 'index'
? `${route.replace('/index', '')}/`
: `${route}/`;
} else {
route = route === '/index'
? '/'
Expand Down Expand Up @@ -92,7 +95,7 @@ module.exports = generateGraph = async (compilation) => {
data: customData || {},
filename,
label,
path: route === '/'
path: route === '/' || relativePagePath.lastIndexOf('/') === 0
? `${relativeWorkspacePath}${filename}`
: `${relativeWorkspacePath}/${filename}`,
route,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Build Greenwood With: ', function() {
});
});

describe('Describe Nested Page', function() {
describe('Describe Page page', function() {
let dom;

beforeEach(async function() {
Expand Down Expand Up @@ -133,6 +133,41 @@ describe('Build Greenwood With: ', function() {
});
});

describe('Describe a page with index in the route filename', function() {
let pluginIndexPageDom;
let pluginHooksIndexPageDom;

beforeEach(async function() {
pluginIndexPageDom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'plugins/index.html'));
pluginHooksIndexPageDom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'plugins/index-hooks/index.html'));
});

it('should output an index.html file for the plugins index page', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'plugins', 'index.html'))).to.be.true;
});

it('should output an index.html file for the plugins page with index in the filename', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'plugins/index-hooks', 'index.html'))).to.be.true;
});

it('should have the expected content in the <body> of the plugins page index.html', function() {
const h2 = pluginIndexPageDom.window.document.querySelector('body h2');
const p = pluginIndexPageDom.window.document.querySelector('body p');

expect(h2.textContent).to.be.equal('Plugins');
expect(p.textContent).to.be.equal('Lorum Ipsum');
});

// TODO - https://github.com/ProjectEvergreen/greenwood/issues/456
xit('should have the expected content in the <body> of the plugins hook index.html with index in the route name', function() {
const h2 = pluginHooksIndexPageDom.window.document.querySelector('body h2');
const p = pluginHooksIndexPageDom.window.document.querySelector('body p');

expect(h2.textContent).to.be.equal('Index Hooks');
expect(p.textContent).to.be.equal('Some more Lorum Ipsum.');
});
});

});

after(function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Index Hooks

Some more Lorum Ipsum.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Plugins

Lorum Ipsum

0 comments on commit b2be2da

Please sign in to comment.