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

better handling for pages with index in their name #462

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/cli/src/transforms/transform.md.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MDTransform extends TransformInterface {
? `${workspace}/pages${url}index`
: `${workspace}/pages${url.replace('.html', '')}`;

return fs.existsSync(`${barePath}.md`) || fs.existsSync(`${barePath.replace('/index', '.md')}`);
return fs.existsSync(`${barePath}.md`) || fs.existsSync(`${barePath.substring(0, barePath.lastIndexOf('/index'))}.md`);
}

async applyTransform() {
Expand All @@ -43,11 +43,10 @@ class MDTransform extends TransformInterface {
: `${workspace}/pages${url.replace('.html', '')}`;

// TODO all this lookup could probably be handled a bit more gracefully perhaps?
// console.debug('this route exists as markdown');
const markdownPath = fs.existsSync(`${barePath}.md`)
? `${barePath}.md`
: fs.existsSync(`${barePath.replace('/index', '.md')}`)
? `${barePath.replace('/index', '.md')}`
: fs.existsSync(`${barePath.substring(0, barePath.lastIndexOf('/index'))}.md`)
? `${barePath.substring(0, barePath.lastIndexOf('/index'))}.md`
: `${workspace}/pages${url.replace('/index.html', '.md')}`;
const markdownContents = await fsp.readFile(markdownPath, 'utf-8');
const rehypePlugins = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
* header/
* header.js
* pages/
* about.md
* plugins/
* index-hooks.md
* index.md
* index.md
* pages.md
* services/
* components.js
* pages/
* pages.js
* components.js
* templates/
* page.html
*/
Expand Down Expand Up @@ -158,8 +161,7 @@ describe('Build Greenwood With: ', function() {
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() {
it('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');

Expand Down