diff options
-rw-r--r-- | lib/index.js | 2 | ||||
-rw-r--r-- | lib/utils/navigation.js | 30 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | test/parsing.js | 10 | ||||
-rw-r--r-- | theme/i18n/de.json | 1 | ||||
-rw-r--r-- | theme/i18n/fr.json | 1 | ||||
-rw-r--r-- | theme/templates/ebook/summary.html | 6 | ||||
-rw-r--r-- | theme/templates/website/includes/summary.html | 6 |
8 files changed, 42 insertions, 16 deletions
diff --git a/lib/index.js b/lib/index.js index a03f39d..44574fd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,7 +19,7 @@ var LOG_OPTION = { var FORMAT_OPTION = { name: "format", description: "Format to build to", - values: ["website", "json"], + values: ["website", "json", "ebook"], defaults: "website" }; diff --git a/lib/utils/navigation.js b/lib/utils/navigation.js index ae4eb9d..21666ad 100644 --- a/lib/utils/navigation.js +++ b/lib/utils/navigation.js @@ -27,19 +27,35 @@ function navigation(summary, files) { files = _.isArray(files) ? files : (_.isString(files) ? [files] : null); // List of all navNodes - // Flatten chapters, then add in default README node if ndeeded etc ... + // Flatten chapters, then add in default README node if needed etc ... var navNodes = flattenChapters(summary.chapters); - var prevNodes = [null].concat(navNodes.slice(0, -1)); - var nextNodes = navNodes.slice(1).concat([null]); // Mapping of prev/next for a give path - var mapping = _.chain(_.zip(navNodes, prevNodes, nextNodes)) - .map(function(nodes) { - var current = nodes[0], prev = nodes[1], next = nodes[2]; + var mapping = _.chain(navNodes) + .map(function(current, i) { + var prev = null, next = null; // Skip if no path if(!current.path) return null; + // Find prev + prev = _.chain(navNodes) + .slice(0, i) + .reverse() + .find(function(node) { + return node.exists && !node.external; + }) + .value(); + + // Find next + next = _.chain(navNodes) + .slice(i+1) + .find(function(node) { + return node.exists && !node.external; + }) + .value(); + + return [current.path, { title: current.title, prev: prev, @@ -47,7 +63,7 @@ function navigation(summary, files) { level: current.level, }]; }) - .filter() + .compact() .object() .value(); diff --git a/package.json b/package.json index 662f168..da31aa4 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "resolve": "0.6.3", "fs-extra": "0.14.0", "fstream-ignore": "1.0.2", - "gitbook-parsers": "0.2.0", + "gitbook-parsers": "0.2.1", "nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747", "nunjucks-autoescape": "0.1.0", "nunjucks-filter": "0.1.0", diff --git a/test/parsing.js b/test/parsing.js index 0166e85..fcda739 100644 --- a/test/parsing.js +++ b/test/parsing.js @@ -18,18 +18,22 @@ describe('Book parsing', function () { assert.equal(LEXED.chapters[0].path, 'intro.md'); assert.equal(LEXED.chapters[0].exists, true); + assert.equal(LEXED.chapters[0].introduction, true); assert.equal(LEXED.chapters[0].external, false); assert.equal(LEXED.chapters[1].path, 'test.md'); assert.equal(LEXED.chapters[1].exists, false); + assert.equal(LEXED.chapters[1].introduction, false); assert.equal(LEXED.chapters[1].external, false); assert.equal(LEXED.chapters[2].path, 'test2.md'); assert.equal(LEXED.chapters[2].exists, false); + assert.equal(LEXED.chapters[2].introduction, false); assert.equal(LEXED.chapters[2].external, false); assert.equal(LEXED.chapters[3].path, 'https://www.google.com'); assert.equal(LEXED.chapters[3].exists, true); + assert.equal(LEXED.chapters[3].introduction, false); assert.equal(LEXED.chapters[3].external, true); }); @@ -69,6 +73,10 @@ describe('Book parsing', function () { assert(NAVIGATION["intro.md"]) assert.equal(NAVIGATION["intro.md"].title, "Introduction"); assert.equal(NAVIGATION["intro.md"].prev, null); - assert.equal(NAVIGATION["intro.md"].next.title, "Chapter 1"); + assert.equal(NAVIGATION["intro.md"].next.title, "Article 1"); + + assert.equal(NAVIGATION["sub/test1.md"].title, "Article 1"); + assert.equal(NAVIGATION["sub/test1.md"].prev.title, "Introduction"); + assert.equal(NAVIGATION["sub/test1.md"].next, null); }); }); diff --git a/theme/i18n/de.json b/theme/i18n/de.json index e45bec7..c5cde18 100644 --- a/theme/i18n/de.json +++ b/theme/i18n/de.json @@ -5,6 +5,7 @@ "GLOSSARY_OPEN": "Glossar", "GITBOOK_LINK": "Veröffentlicht mit GitBook", "SUMMARY": "Inhaltsverzeichnis", + "SUMMARY_INTRODUCTION": "Einführung", "SUMMARY_TOGGLE": "Inhaltsverzeichnis", "SEARCH_TOGGLE": "Suche", "SEARCH_PLACEHOLDER": "Suchbegriff eingeben", diff --git a/theme/i18n/fr.json b/theme/i18n/fr.json index eedc8ab..8692174 100644 --- a/theme/i18n/fr.json +++ b/theme/i18n/fr.json @@ -5,6 +5,7 @@ "GLOSSARY_OPEN": "Glossaire", "GITBOOK_LINK": "Publié avec GitBook", "SUMMARY": "Table des matières", + "SUMMARY_INTRODUCTION": "Introduction", "SUMMARY_TOGGLE": "Table des matières", "SEARCH_TOGGLE": "Recherche", "SEARCH_PLACEHOLDER": "Tapez pour rechercher", diff --git a/theme/templates/ebook/summary.html b/theme/templates/ebook/summary.html index 16de1e8..c0d6d1e 100644 --- a/theme/templates/ebook/summary.html +++ b/theme/templates/ebook/summary.html @@ -5,9 +5,9 @@ {% macro articles(_articles) %} {% for item in _articles %} <li> - {% if item.path %} - {% if item.external %} - <a href="{{ basePath }}/{{ item.path|contentLink }}">{{ item.title }}</a> + {% if item.path and item.exists %} + {% if not item.external %} + <a href="{{ basePath }}/{{ item.path|contentLink }}">{% if item.introduction %}{% i18n "SUMMARY_INTRODUCTION" %}Introduction{% endi18n %}{% else %}{{ item.title }}{% endif %}</a> {% else %} <a target="_blank" href="{{ item.path }}">{{ item.title }}</a> {% endif %} diff --git a/theme/templates/website/includes/summary.html b/theme/templates/website/includes/summary.html index 235b81f..5f09e13 100644 --- a/theme/templates/website/includes/summary.html +++ b/theme/templates/website/includes/summary.html @@ -1,14 +1,14 @@ {% macro articles(_articles) %} {% for item in _articles %} <li class="chapter {% if item.path == _input %}active{% endif %}" data-level="{{ item.level }}" {% if item.path and not item.external %}data-path="{{ item.path|contentLink }}"{% endif %}> - {% if item.path %} + {% if item.path and item.exists %} {% if not item.external %} <a href="{{ basePath }}/{{ item.path|contentLink }}"> <i class="fa fa-check"></i> {% if item.level != "0" %} <b>{{ item.level }}.</b> {% endif %} - {{ item.title }} + {% if item.introduction %}{% i18n "SUMMARY_INTRODUCTION" %}Introduction{% endi18n %}{% else %}{{ item.title }}{% endif %} </a> {% else %} <a target="_blank" href="{{ item.path }}"> @@ -16,7 +16,7 @@ {% if item.level != "0" %} <b>{{ item.level }}.</b> {% endif %} - {{ item.title }} + {{ item.title }} </a> {% endif %} {% else %} |