diff options
-rw-r--r-- | CHANGES.md | 4 | ||||
-rw-r--r-- | lib/book.js | 26 | ||||
-rw-r--r-- | package.json | 6 | ||||
-rw-r--r-- | test/books/init/.gitignore | 3 | ||||
-rw-r--r-- | test/books/init/SUMMARY.md | 6 | ||||
-rw-r--r-- | test/init.js | 23 | ||||
-rw-r--r-- | theme/templates/website/layout.html | 2 |
7 files changed, 55 insertions, 15 deletions
@@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## 2.0.3 +- Fix `gitbook init` for SUMMARY with empty entries +- Fix escaping of code blocks in markdown + ## 2.0.2 - Fix relative links in windows - Improve watcher in serve command (switch to chokidar) diff --git a/lib/book.js b/lib/book.js index e61d771..2e0ab58 100644 --- a/lib/book.js +++ b/lib/book.js @@ -789,20 +789,19 @@ Book.prototype.normError = function(err, opts, defs) { }; // Init and return a book -Book.init = function(root) { - var book = new Book(root); +Book.init = function(root, opts) { + var book = new Book(root, opts); var extensionToUse = ".md"; var chaptersPaths = function(chapters) { return _.reduce(chapters || [], function(accu, chapter) { - if (!chapter.path) return accu; + var o = { + title: chapter.title + }; + if (chapter.path) o.path = chapter.path; + return accu.concat( - _.filter([ - { - title: chapter.title, - path: chapter.path - } - ].concat(chaptersPaths(chapter.articles))) + [o].concat(chaptersPaths(chapter.articles)) ); }, []); }; @@ -839,12 +838,17 @@ Book.init = function(root) { .then(function(chapters) { // Create files that don't exist return Q.all(_.map(chapters, function(chapter) { + if (!chapter.path) return Q(); var absolutePath = path.resolve(book.root, chapter.path); return fs.exists(absolutePath) .then(function(exists) { - book.log.info.ln("create", chapter.path); - if(exists) return; + if(exists) { + book.log.info.ln("found", chapter.path); + return; + } else { + book.log.info.ln("create", chapter.path); + } return fs.mkdirp(path.dirname(absolutePath)) .then(function() { diff --git a/package.json b/package.json index 5fb7afa..86278ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitbook", - "version": "2.0.2", + "version": "2.0.3", "homepage": "https://www.gitbook.com", "description": "Library and cmd utility to generate GitBooks", "main": "lib/index.js", @@ -12,7 +12,7 @@ "resolve": "0.6.3", "fs-extra": "0.16.5", "fstream-ignore": "1.0.2", - "gitbook-parsers": "0.7.4", + "gitbook-parsers": "0.7.5", "nunjucks": "1.3.0", "nunjucks-autoescape": "0.1.1", "nunjucks-filter": "0.1.0", @@ -61,7 +61,7 @@ "gitbook" ], "author": "FriendCode Inc. <contact@gitbook.com>", - "license": "Apache 2", + "license": "Apache-2.0", "bugs": { "url": "https://github.com/GitbookIO/gitbook/issues" }, diff --git a/test/books/init/.gitignore b/test/books/init/.gitignore new file mode 100644 index 0000000..8a88b2a --- /dev/null +++ b/test/books/init/.gitignore @@ -0,0 +1,3 @@ +* +!SUMMARY.md +!.gitignore diff --git a/test/books/init/SUMMARY.md b/test/books/init/SUMMARY.md new file mode 100644 index 0000000..1e63aed --- /dev/null +++ b/test/books/init/SUMMARY.md @@ -0,0 +1,6 @@ +# Summary + +* [Hello](hello.md) +* [Hello 2](hello2.md) +* Hello 3 + * [Hello 4](hello3/hello4.md) diff --git a/test/init.js b/test/init.js new file mode 100644 index 0000000..3ba701f --- /dev/null +++ b/test/init.js @@ -0,0 +1,23 @@ +var fs = require('fs'); +var path = require('path'); +var should = require('should'); + +var Book = require('../').Book; +var LOG_LEVELS = require('../').LOG_LEVELS; + +describe('Init Books', function () { + var initRoot; + + before(function() { + initRoot = path.resolve(__dirname, "books/init"); + return Book.init(initRoot, { + logLevel: LOG_LEVELS.DISABLED, + }); + }); + + it('should create all chapters', function() { + should(fs.existsSync(path.resolve(initRoot, "hello.md"))).be.ok; + should(fs.existsSync(path.resolve(initRoot, "hello2.md"))).be.ok; + should(fs.existsSync(path.resolve(initRoot, "hello3/hello4.md"))).be.ok; + }); +}); diff --git a/theme/templates/website/layout.html b/theme/templates/website/layout.html index 8ab807f..9e66799 100644 --- a/theme/templates/website/layout.html +++ b/theme/templates/website/layout.html @@ -17,12 +17,12 @@ <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="apple-touch-icon-precomposed" sizes="152x152" href="{{ staticBase }}/images/apple-touch-icon-precomposed-152.png"> <link rel="shortcut icon" href="{{ staticBase }}/images/favicon.ico" type="image/x-icon"> + {% block style %}{% endblock %} {% block head %}{% endblock %} {{ htmlSnippet("head:end")|default("")|safe }} </head> <body> {{ htmlSnippet("body:start")|default("")|safe }} - {% block style %}{% endblock %} {% block content %}{% endblock %} {% block javascript %}{% endblock %} {{ htmlSnippet("body:end")|default("")|safe }} |