mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 10:33:22 +00:00
Change summary data format
Simplify chapter objects, by making them identical to article objects besides the .articles attribute
This commit is contained in:
@@ -90,10 +90,9 @@ function parseArticle(nodes) {
|
||||
}
|
||||
|
||||
function parseChapter(nodes) {
|
||||
return {
|
||||
chapter: parseTitle(_.first(nodes).text),
|
||||
return _.extend(parseTitle(_.first(nodes).text), {
|
||||
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function parseSummary(src) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<li class="divider"></li>
|
||||
{% for item in summary.chapters %}
|
||||
<li>
|
||||
<a href="{{ basePath }}/{{ item.chapter.path }}">{{ item.chapter.title }}</a>
|
||||
<a href="{{ basePath }}/{{ item.path }}">{{ item.title }}</a>
|
||||
{% if item.articles.length > 0 %}
|
||||
<ul class="articles">
|
||||
{% for article in item.articles %}
|
||||
|
||||
+12
-12
@@ -23,21 +23,21 @@ describe('Summary parsing', function () {
|
||||
});
|
||||
|
||||
it('should detect paths and titles', function() {
|
||||
assert(LEXED.chapters[0].chapter.path);
|
||||
assert(LEXED.chapters[1].chapter.path);
|
||||
assert(LEXED.chapters[2].chapter.path);
|
||||
assert(LEXED.chapters[0].path);
|
||||
assert(LEXED.chapters[1].path);
|
||||
assert(LEXED.chapters[2].path);
|
||||
|
||||
assert(LEXED.chapters[0].chapter.title);
|
||||
assert(LEXED.chapters[1].chapter.title);
|
||||
assert(LEXED.chapters[2].chapter.title);
|
||||
assert(LEXED.chapters[0].title);
|
||||
assert(LEXED.chapters[1].title);
|
||||
assert(LEXED.chapters[2].title);
|
||||
});
|
||||
|
||||
it('should normalize paths from .md to .html', function() {
|
||||
assert.equal(LEXED.chapters[0].chapter.path,'chapter-1/README.html');
|
||||
assert.equal(LEXED.chapters[0].chapter._path,'chapter-1/README.md');
|
||||
assert.equal(LEXED.chapters[1].chapter.path,'chapter-2/README.html');
|
||||
assert.equal(LEXED.chapters[1].chapter._path,'chapter-2/README.md');
|
||||
assert.equal(LEXED.chapters[2].chapter.path,'chapter-3/README.html');
|
||||
assert.equal(LEXED.chapters[2].chapter._path,'chapter-3/README.md');
|
||||
assert.equal(LEXED.chapters[0].path,'chapter-1/README.html');
|
||||
assert.equal(LEXED.chapters[0]._path,'chapter-1/README.md');
|
||||
assert.equal(LEXED.chapters[1].path,'chapter-2/README.html');
|
||||
assert.equal(LEXED.chapters[1]._path,'chapter-2/README.md');
|
||||
assert.equal(LEXED.chapters[2].path,'chapter-3/README.html');
|
||||
assert.equal(LEXED.chapters[2]._path,'chapter-3/README.md');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user