summaryrefslogtreecommitdiffstats
path: root/lib/backbone/summary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-28 14:47:34 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-28 14:47:34 +0100
commit4aa66338fce505566a2fe6ba6aee79ddf3f656a2 (patch)
treeffce4b558735f6a41228542f8c36e3a6ba1e562d /lib/backbone/summary.js
parent8cda844ef12cf87525024348c104413def02ed7f (diff)
downloadgitbook-4aa66338fce505566a2fe6ba6aee79ddf3f656a2.zip
gitbook-4aa66338fce505566a2fe6ba6aee79ddf3f656a2.tar.gz
gitbook-4aa66338fce505566a2fe6ba6aee79ddf3f656a2.tar.bz2
Add init command
Diffstat (limited to 'lib/backbone/summary.js')
-rw-r--r--lib/backbone/summary.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js
index 4ae3453..a79b1e9 100644
--- a/lib/backbone/summary.js
+++ b/lib/backbone/summary.js
@@ -6,7 +6,6 @@ var location = require('../utils/location');
var error = require('../utils/error');
var BackboneFile = require('./file');
-
/*
An article represent an entry in the Summary.
It's defined by a title, a reference, and children articles,
@@ -37,8 +36,9 @@ function TOCArticle(def, parent) {
var parts = url.parse(this.ref);
if (!this.isExternal()) {
- this.path = parts.pathname;
- this.anchor = parts.hash;
+ var parts = this.ref.split('#');
+ this.path = (parts.length > 1? parts.slice(0, -1).join('#') : this.ref);
+ this.anchor = (parts.length > 1? '#' + _.last(parts) : null);
}
}
@@ -264,6 +264,17 @@ Summary.prototype.find = function(filter) {
return result;
};
+// Flatten the list of articles
+Summary.prototype.flatten = function() {
+ var result = [];
+
+ this.walk(function(article) {
+ result.push(article);
+ });
+
+ return result;
+};
+
// Return the first TOCArticle for a specific page (or path)
Summary.prototype.getArticle = function(page) {
if (!_.isString(page)) page = page.path;