Compare commits

...

6 Commits

Author SHA1 Message Date
Samy Pessé 16128c7e60 Bump version to 0.5.6 2014-06-24 12:35:13 +02:00
Samy Pessé 8b6a80cffb Fix error when chapters list is empty
Fix GitbookIO/gitbook.io#101 and GitbookIO/gitbook.io#102
2014-06-24 12:34:29 +02:00
Aaron O'Mullan 86f8a9d8fb Remove useless (and bad) sort on progress
Fixes bad ordering of chapters on gitbook.io
2014-06-20 03:40:47 -07:00
Aaron O'Mullan 790dfd601e Add csharp language highlight mapping
Fixes #327
2014-06-18 11:26:50 -07:00
Aaron O'Mullan 3426428142 Bump version to 0.5.5 2014-06-18 00:25:23 -07:00
Aaron O'Mullan 6c5c8e6eb7 Fix LANGS.md parsing
And cleanup Summary parsing
2014-06-17 16:18:08 -07:00
5 changed files with 31 additions and 21 deletions
+8 -6
View File
@@ -1,13 +1,14 @@
var _ = require("lodash")
var parseSummary = require("./summary");
var _ = require("lodash");
var parseEntries = require("./summary").entries;
var parseLangs = function(content) {
var summary = parseSummary(content);
var entries = parseEntries(content);
return {
list: _.chain(summary.chapters)
list: _.chain(entries)
.filter(function(entry) {
return entry.path != null;
return Boolean(entry.path);
})
.map(function(entry) {
return {
@@ -17,7 +18,8 @@ var parseLangs = function(content) {
};
})
.value()
}
};
};
module.exports = parseLangs;
-3
View File
@@ -11,9 +11,6 @@ var calculProgress = function(navigation, current) {
nav.path = path;
return nav;
})
.sortBy(function(nav) {
return parseFloat(nav.level);
})
.map(function(nav, i) {
// Calcul percent
nav.percent = (i * 100) / Math.max((n - 1), 1);
+21 -11
View File
@@ -87,6 +87,9 @@ function parseTitle(src, nums) {
}
function parseChapter(nodes, nums) {
// Convert single number to an array
nums = _.isArray(nums) ? nums : [nums];
return _.extend(parseTitle(_.first(nodes).text, nums), {
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), function(nodes, i) {
return parseChapter(nodes, nums.concat(i + 1));
@@ -97,11 +100,13 @@ function parseChapter(nodes, nums) {
function defaultChapterList(chapterList) {
var first = _.first(chapterList);
var chapter = parseChapter(first, [0]);
if (first) {
var chapter = parseChapter(first, [0]);
// Already have README node, we're good to go
if(chapter.path === 'README.md') {
return chapterList;
// Already have README node, we're good to go
if(chapter.path === 'README.md') {
return chapterList;
}
}
return [
@@ -109,26 +114,31 @@ function defaultChapterList(chapterList) {
].concat(chapterList);
}
function parseSummary(src) {
function listGroups(src) {
var nodes = marked.lexer(src);
// Get out list of chapters
var chapterList = listSplit(
// Get out groups of lists
return listSplit(
filterList(nodes),
'list_item_start', 'list_item_end'
);
}
function parseSummary(src) {
// Split out chapter sections
var chapters = defaultChapterList(chapterList)
.map(function(nodes, i) {
return parseChapter(nodes, [i]);
});
var chapters = defaultChapterList(listGroups(src))
.map(parseChapter);
return {
chapters: chapters
};
}
function parseEntries (src) {
return listGroups(src).map(parseChapter);
}
// Exports
module.exports = parseSummary;
module.exports.entries = parseEntries;
+1
View File
@@ -2,6 +2,7 @@ var MAP = {
'py': 'python',
'js': 'javascript',
'rb': 'ruby',
'csharp': 'cs',
};
function normalize(lang) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "gitbook",
"version": "0.5.4",
"version": "0.5.6",
"homepage": "http://www.gitbook.io/",
"description": "Library and cmd utility to generate GitBooks",
"main": "lib/index.js",