diff --git a/packages/cli/src/plugins/resource/plugin-standard-html.js b/packages/cli/src/plugins/resource/plugin-standard-html.js index 69a236ac0..cf34e7689 100644 --- a/packages/cli/src/plugins/resource/plugin-standard-html.js +++ b/packages/cli/src/plugins/resource/plugin-standard-html.js @@ -20,13 +20,18 @@ const unified = require('unified'); // general refactoring const getPageTemplate = (barePath, workspace, template) => { const templatesDir = path.join(workspace, 'templates'); + const pageIsHtmlPath = `${barePath.substring(0, barePath.lastIndexOf('/index'))}.html`; if (template && fs.existsSync(`${templatesDir}/${template}.html`)) { // use a predefined template, usually from markdown frontmatter contents = fs.readFileSync(`${templatesDir}/${template}.html`, 'utf-8'); - } else if (fs.existsSync(`${barePath}.html`)) { + } else if (fs.existsSync(`${barePath}.html`) || fs.existsSync(pageIsHtmlPath)) { // if the page is already HTML, use that as the template - contents = fs.readFileSync(`${barePath}.html`, 'utf-8'); + const indexPath = fs.existsSync(pageIsHtmlPath) + ? pageIsHtmlPath + : `${barePath}.html`; + + contents = fs.readFileSync(indexPath, 'utf-8'); } else if (fs.existsSync(`${templatesDir}/page.html`)) { // else look for default page template contents = fs.readFileSync(`${templatesDir}/page.html`, 'utf-8'); diff --git a/packages/cli/test/cases/build.default.workspace-top-level-pages/build.default.workspace-top-level-pages.spec.js b/packages/cli/test/cases/build.default.workspace-top-level-pages/build.default.workspace-top-level-pages.spec.js new file mode 100644 index 000000000..1400a5791 --- /dev/null +++ b/packages/cli/test/cases/build.default.workspace-top-level-pages/build.default.workspace-top-level-pages.spec.js @@ -0,0 +1,114 @@ +/* + * Use Case + * Run Greenwood with default config and mixed HTML and markdown top level pages. + * + * Result + * Test for correct page output and layout. + * + * Command + * greenwood build + * + * User Config + * None (Greenwood default) + * + * User Workspace + * src/ + * pages/ + * about.html + * contact.md + * index.html + */ +const expect = require('chai').expect; +const fs = require('fs'); +const { JSDOM } = require('jsdom'); +const path = require('path'); +const TestBed = require('../../../../../test/test-bed'); + +describe('Build Greenwood With: ', function() { + const LABEL = 'Default Greenwood Configuration and Default Workspace w/ Top Level Pages'; + let setup; + + before(async function() { + setup = new TestBed(); + this.context = await setup.setupTestBed(__dirname); + }); + + describe(LABEL, function() { + before(async function() { + await setup.runGreenwoodCommand('build'); + }); + + // TODO runSmokeTest(['public', 'not-found', 'index'], LABEL); + runSmokeTest(['public'], LABEL); + + describe('Home (index) Page', function() { + let dom; + + before(async function() { + dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'index.html')); + }); + + it('should create a top level home (index) page with just an index.html', function() { + expect(fs.existsSync(path.join(this.context.publicDir, './index.html'))).to.be.true; + }); + + it('should have the correct content for the home page', function() { + const h1Tags = dom.window.document.querySelectorAll('h1'); + + expect(h1Tags.length).to.equal(1); + expect(h1Tags[0].textContent).to.equal('Hello from the home page!!!!'); + }); + }); + + describe('About Page', function() { + let dom; + + before(async function() { + dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'about', 'index.html')); + }); + + it('should create a top level about page with a directory and index.html', function() { + expect(fs.existsSync(path.join(this.context.publicDir, 'about', 'index.html'))).to.be.true; + }); + + it('should have the correct content for the about page', function() { + const h1Tags = dom.window.document.querySelectorAll('h1'); + const pTags = dom.window.document.querySelectorAll('p'); + + expect(h1Tags.length).to.equal(1); + expect(h1Tags[0].textContent).to.equal('Hello from about.html'); + + expect(pTags.length).to.equal(1); + expect(pTags[0].textContent).to.equal('Lorum Ipsum'); + }); + }); + + describe('Contact Page', function() { + let dom; + + before(async function() { + dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'contact', 'index.html')); + }); + + it('should create a top level contact page with a directory and index.html', function() { + expect(fs.existsSync(path.join(this.context.publicDir, 'contact', 'index.html'))).to.be.true; + }); + + it('should have the correct content for the contact page', function() { + const h3Tags = dom.window.document.querySelectorAll('h3'); + const pTags = dom.window.document.querySelectorAll('p'); + + expect(h3Tags.length).to.equal(1); + expect(h3Tags[0].textContent).to.equal('Contact Page'); + + expect(pTags.length).to.equal(1); + expect(pTags[0].textContent).to.equal('Thanks for contacting us.'); + }); + }); + }); + + after(function() { + setup.teardownTestBed(); + }); + +}); \ No newline at end of file diff --git a/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/about.html b/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/about.html new file mode 100644 index 000000000..c3e165d74 --- /dev/null +++ b/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/about.html @@ -0,0 +1,9 @@ + + + + +

Hello from about.html

+

Lorum Ipsum

+ + + \ No newline at end of file diff --git a/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/contact.md b/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/contact.md new file mode 100644 index 000000000..f6d45df3c --- /dev/null +++ b/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/contact.md @@ -0,0 +1,3 @@ +### Contact Page + +Thanks for contacting us. \ No newline at end of file diff --git a/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/index.html b/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/index.html new file mode 100644 index 000000000..2b9bd0170 --- /dev/null +++ b/packages/cli/test/cases/build.default.workspace-top-level-pages/src/pages/index.html @@ -0,0 +1,8 @@ + + + + +

Hello from the home page!!!!

+ + + \ No newline at end of file