diff --git a/README.md b/README.md index e50e6c9..2db661c 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,6 @@ Pages and posts must created in the `src/content/pages` and `src/content/posts` Pages and posts are Markdown files with a YAML front-matter block. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines. Here is a basic example: --- - slug: index title: Home template: index.hbs --- @@ -119,9 +118,9 @@ Pages and posts are Markdown files with a YAML front-matter block. The front mat Between these triple-dashed lines, you can set predefined variables (see below). These variables will then be available to you in any Handlebars templates or includes that the page or post in question relies on. -* slug (required) - the URL slug which is used as the directory name when the page or post is built * title (required) - the title of the page or post * template (required) - the Handlebars template to use to compile the page or post +* slug (optional) - the URL slug which is used as the directory name when the page or post is built * date (optional) - used for posts and in the format YYYY-MM-DD * author (optional) - used for posts and the author key in the `site.json` file * status (optional) - set to 'draft' to ignore the page or post when running the generator @@ -161,4 +160,4 @@ Helpers are available to your Handlebar templates and partials, these are: The example site is a good place to start and shows a basic structure of a site with templates and content. -If you encounter any issues or have any feedback, please [send me a tweet](http://twitter.com/ducksoupdev) or raise a bug on the issue tracker. \ No newline at end of file +If you encounter any issues or have any feedback, please [send me a tweet](http://twitter.com/ducksoupdev) or raise a bug on the issue tracker. diff --git a/gulp/tests/compile-pages.spec.js b/gulp/tests/compile-pages.spec.js index e9bed45..75f7e4d 100644 --- a/gulp/tests/compile-pages.spec.js +++ b/gulp/tests/compile-pages.spec.js @@ -1,4 +1,4 @@ -(function () { +(function() { 'use strict'; var compilePages = require('../lib/compile-pages'), @@ -13,7 +13,7 @@ var rootPath = '/tmp/compile-pages'; var doneStub, errorStub; - before(function () { + before(function() { doneStub = sinon.stub(); errorStub = sinon.stub(); @@ -31,57 +31,150 @@ '/build/content', '/build/content/pages', '/build/content/posts' - ].forEach(function (dir) { - if (!fs.existsSync(rootPath + dir)) { - fs.mkdirSync(rootPath + dir); - } - }); + ].forEach(function(dir) { + if (!fs.existsSync(rootPath + dir)) { + fs.mkdirSync(rootPath + dir); + } + }); // set-up files: - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', {encoding: 'utf8'}); - fs.writeFileSync(rootPath + '/src/templates/page.hbs', '
Test page content
"}', {encoding: 'utf8'}); - compilePages.run(rootPath, done, errorStub); + describe('When compiling a page', function() { + before(function(done) { + fs.writeFileSync(rootPath + + '/build/content/pages/test-page.json', + '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"Test page content
"}', { + encoding: 'utf8' + }); + compilePages.run(rootPath, done, + errorStub); }); - it('Should create the static page', function () { - expect(fs.existsSync(rootPath + '/build/test-page/index.html')).to.be.true; + it('Should create the static page', function() { + expect(fs.existsSync(rootPath + + '/build/test-page/index.html' + )).to.be.true; }); - it('Should have the correct page content', function () { - expect(fs.readFileSync(rootPath + '/build/test-page/index.html', 'utf8')).to.equal('Test page content
Test page content
Test page content
"}', { + encoding: 'utf8' + }); + compilePages.run(rootPath, done, + errorStub); }); + + it('Should create the static page', function() { + expect(fs.existsSync(rootPath + + '/build/test-page-no-slug/index.html' + )).to.be.true; + }); + + it('Should have the correct page content', + function() { + expect(fs.readFileSync(rootPath + + '/build/test-page-no-slug/index.html', + 'utf8')).to.equal( + 'Test page content
Test post content
"}', {encoding: 'utf8'}); - compilePages.run(rootPath, done, errorStub); + describe('When compiling a post', function() { + before(function(done) { + fs.writeFileSync(rootPath + + '/build/content/posts/test-post.json', + '{"slug":"test-post","title":"Test post","date":"2014-06-11","template":"post.hbs","body":"Test post content
"}', { + encoding: 'utf8' + }); + compilePages.run(rootPath, done, + errorStub); }); - it('Should create the static post', function () { - expect(fs.existsSync(rootPath + '/build/test-post/index.html')).to.be.true; + it('Should create the static post', function() { + expect(fs.existsSync(rootPath + + '/build/test-post/index.html' + )).to.be.true; + }); + + it('Should have the correct post content', + function() { + expect(fs.readFileSync(rootPath + + '/build/test-post/index.html', + 'utf8')).to.equal( + 'Test post content
Test post content
"}', { + encoding: 'utf8' + }); + compilePages.run(rootPath, done, + errorStub); }); - it('Should have the correct post content', function () { - expect(fs.readFileSync(rootPath + '/build/test-post/index.html', 'utf8')).to.equal('Test post content
Test post content
Test page content
"}', {encoding: 'utf8'}); + fs.writeFileSync(rootPath + + '/build/content/pages/test-page.json', + '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"Test page content
"}', { + encoding: 'utf8' + }); mockery.enable({ warnOnReplace: false, @@ -93,20 +186,27 @@ promisesListStub = { filter: function() { - return [Promise.reject('An error occurred')]; + return [Promise.reject( + 'An error occurred' + )]; } }; - mockery.registerMock('../lib/promises', promisesListStub); + mockery.registerMock( + '../lib/promises', + promisesListStub); - newCompilePages = require('../lib/compile-pages'); + newCompilePages = require( + '../lib/compile-pages'); - newCompilePages.run(rootPath, function() { - done(); - }, function(err) { - errorStub(err); - done(); - }); + newCompilePages.run(rootPath, + function() { + done(); + }, + function(err) { + errorStub(err); + done(); + }); }); @@ -115,52 +215,83 @@ }); afterEach(function() { - mockery.deregisterMock('../lib/promises'); + mockery.deregisterMock( + '../lib/promises'); mockery.disable(); }); }); - describe('When compiling posts and excluding draft templates', function () { - before(function (done) { - fs.writeFileSync(rootPath + '/build/content/posts/test-draft-post.json', '{"slug":"test-draft-post","title":"Test draft post","date":"2014-06-11","template":"post.hbs","status":"draft","body":"Test draft post content
"}', {encoding: 'utf8'}); - compilePages.run(rootPath, done, errorStub); - }); + describe( + 'When compiling posts and excluding draft templates', + function() { + before(function(done) { + fs.writeFileSync(rootPath + + '/build/content/posts/test-draft-post.json', + '{"slug":"test-draft-post","title":"Test draft post","date":"2014-06-11","template":"post.hbs","status":"draft","body":"Test draft post content
"}', { + encoding: 'utf8' + }); + compilePages.run(rootPath, done, + errorStub); + }); - it('Should not create the static post', function () { - expect(fs.existsSync(rootPath + '/build/test-draft-post/index.html')).to.be.false; + it('Should not create the static post', + function() { + expect(fs.existsSync(rootPath + + '/build/test-draft-post/index.html' + )).to.be.false; + }); }); - }); - describe('When compiling posts and including tags', function () { - before(function (done) { - fs.writeFileSync(rootPath + '/src/templates/post.hbs', 'Test tagged post content
"}', {encoding: 'utf8'}); - compilePages.run(rootPath, done, errorStub); - }); + describe('When compiling posts and including tags', + function() { + before(function(done) { + fs.writeFileSync(rootPath + + '/src/templates/post.hbs', + 'Test tagged post content
"}', { + encoding: 'utf8' + }); + compilePages.run(rootPath, done, + errorStub); + }); - it('Should have the correct post content', function () { - expect(fs.readFileSync(rootPath + '/build/test-tagged-post/index.html', 'utf8')).to.equal('Test tagged post content
Test tagged post content