mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-26 12:18:01 +00:00
Compare commits
16 Commits
3.0.0-pre.15
...
3.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| d1e226dba5 | |||
| 1923d28d71 | |||
| 484a306adb | |||
| 5bfc9f2f56 | |||
| 86a65e5287 | |||
| 956d301dd7 | |||
| 00d1a7b5a6 | |||
| 2718c9c017 | |||
| 3234c1e03f | |||
| c8f8eece92 | |||
| 7394efa9dc | |||
| 3e4241fc88 | |||
| a5ae79604c | |||
| fc4bdd68a1 | |||
| f83975b022 | |||
| 167d3957bf |
@@ -5,13 +5,18 @@ init:
|
||||
# Test against these versions of Node.js.
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "6"
|
||||
- nodejs_version: "5"
|
||||
- nodejs_version: "4"
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
# Install scripts. (runs after repo cloning)
|
||||
install:
|
||||
# Get the latest stable version of Node.js or io.js
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- set CI=true
|
||||
# install svgexport
|
||||
- npm install svgexport -g
|
||||
# install modules
|
||||
@@ -27,3 +32,7 @@ test_script:
|
||||
|
||||
# Don't actually build.
|
||||
build: off
|
||||
|
||||
# Clone only last commit
|
||||
shallow_clone: true
|
||||
clone_depth: 1
|
||||
|
||||
@@ -7,6 +7,7 @@ GitBook allows you to customize your book using a flexible configuration. These
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| `root` | Path to the root folder containing all the book's files, except `book.json`|
|
||||
| `structure` | To specify paths for Readme, Summary, Glossary etc. See [Structure paragraph](#structure). |
|
||||
| `title` | Title of your book, default value is extracted from the README. On GitBook.com this field is pre-filled. |
|
||||
| `description` | Description of your book, default value is extracted from the README. On GitBook.com this field is pre-filled. |
|
||||
| `author` | Name of the author. On GitBook.com this field is pre-filled. |
|
||||
@@ -32,6 +33,18 @@ Since version 3.0.0, GitBook can use themes. See [the theming section](themes/RE
|
||||
| -------- | ----------- |
|
||||
| `theme` | The theme to use for the book |
|
||||
|
||||
### Structure
|
||||
|
||||
In addition to the `root` variable, you can tell Gitbook the name of the files for Readme, Summary, Glossary, Languages (instead of using the default names such as `README.md`).
|
||||
These files must be at the root of your book (or the root of every language book). Paths such as `dir/MY_README.md` are not accepted.
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| `structure.readme` | Readme file name (defaults to `README.md`) |
|
||||
| `structure.summary` | Summary file name (defaults to `SUMMARY.md`) |
|
||||
| `structure.glossary` | Glossary file name (defaults to `GLOSSARY.md`) |
|
||||
| `structure.languages` | Languages file name (defaults to `LANGS.md`) |
|
||||
|
||||
### PDF Options
|
||||
|
||||
PDF Output can be customized using a set of options in the `book.json`:
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ var filepath = output.resolve('myimage.png');
|
||||
var fileurl = output.toURL('mychapter/README.md');
|
||||
|
||||
// Write a file in the output folder
|
||||
output.write('hello.txt', 'Hello World')
|
||||
output.writeFile('hello.txt', 'Hello World')
|
||||
.then(function() { ... });
|
||||
|
||||
// Copy a file to the output folder
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ It integrates well with the [GitBook Editor](https://www.gitbook.com/editor).
|
||||
|
||||
Installing GitBook is easy and straightforward. Your system just needs to meet these two requirements:
|
||||
|
||||
* NodeJS (v4.0.0 and above are adviced)
|
||||
* NodeJS (v4.0.0 and above is recommended)
|
||||
* Windows, Linux, Unix, or Mac OS X
|
||||
|
||||
##### Install with NPM
|
||||
|
||||
@@ -8,6 +8,7 @@ var deprecate = require('./deprecate');
|
||||
var fileToURL = require('../output/helper/fileToURL');
|
||||
var defaultBlocks = require('../constants/defaultBlocks');
|
||||
var gitbook = require('../gitbook');
|
||||
var parsers = require('../parsers');
|
||||
|
||||
var encodeConfig = require('./encodeConfig');
|
||||
var encodeSummary = require('./encodeSummary');
|
||||
@@ -95,6 +96,34 @@ function encodeGlobal(output) {
|
||||
return encodePage(output, page);
|
||||
},
|
||||
|
||||
/**
|
||||
Render a block of text (markdown/asciidoc)
|
||||
|
||||
@param {String} type
|
||||
@param {String} text
|
||||
@return {Promise<String>}
|
||||
*/
|
||||
renderBlock: function(type, text) {
|
||||
var parser = parsers.get(type);
|
||||
|
||||
return parser.parsePage(text)
|
||||
.get('content');
|
||||
},
|
||||
|
||||
/**
|
||||
Render an inline text (markdown/asciidoc)
|
||||
|
||||
@param {String} type
|
||||
@param {String} text
|
||||
@return {Promise<String>}
|
||||
*/
|
||||
renderInline: function(type, text) {
|
||||
var parser = parsers.get(type);
|
||||
|
||||
return parser.parseInline(text)
|
||||
.get('content');
|
||||
},
|
||||
|
||||
template: {
|
||||
/**
|
||||
Apply a templating block and returns its result
|
||||
@@ -142,6 +171,21 @@ function encodeGlobal(output) {
|
||||
return fileToURL(output, filePath);
|
||||
},
|
||||
|
||||
/**
|
||||
Check that a file exists.
|
||||
|
||||
@param {String} fileName
|
||||
@return {Promise}
|
||||
*/
|
||||
hasFile: function(fileName, content) {
|
||||
return Promise()
|
||||
.then(function() {
|
||||
var filePath = PathUtils.resolveInRoot(outputFolder, fileName);
|
||||
|
||||
return fs.exists(filePath);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Write a file to the output folder,
|
||||
It creates the required folder
|
||||
@@ -160,6 +204,27 @@ function encodeGlobal(output) {
|
||||
return fs.writeFile(filePath, content);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Copy a file to the output folder
|
||||
It creates the required folder.
|
||||
|
||||
@param {String} inputFile
|
||||
@param {String} outputFile
|
||||
@param {Buffer} content
|
||||
@return {Promise}
|
||||
*/
|
||||
copyFile: function(inputFile, outputFile, content) {
|
||||
return Promise()
|
||||
.then(function() {
|
||||
var outputFilePath = PathUtils.resolveInRoot(outputFolder, outputFile);
|
||||
|
||||
return fs.ensureFile(outputFilePath)
|
||||
.then(function() {
|
||||
return fs.copy(inputFile, outputFilePath);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+5
-1
@@ -11,5 +11,9 @@ module.exports = {
|
||||
|
||||
// Modifiers
|
||||
SummaryModifier: Modifiers.Summary,
|
||||
ConfigModifier: Modifiers.Config
|
||||
ConfigModifier: Modifiers.Config,
|
||||
|
||||
// Constants
|
||||
CONFIG_FILES: require('./constants/configFiles.js'),
|
||||
IGNORE_FILES: require('./constants/ignoreFiles.js')
|
||||
};
|
||||
|
||||
+6
-2
@@ -324,12 +324,16 @@ Book.prototype.getDefaultGlossaryPath = function() {
|
||||
*/
|
||||
Book.createFromParent = function createFromParent(parent, language) {
|
||||
var ignore = parent.getIgnore();
|
||||
var config = parent.getConfig();
|
||||
|
||||
// Set language in configuration
|
||||
config = config.setValue('language', language);
|
||||
|
||||
return new Book({
|
||||
// Inherits config. logegr and list of ignored files
|
||||
logger: parent.getLogger(),
|
||||
config: parent.getConfig(),
|
||||
ignore: Ignore().add(ignore),
|
||||
config: config,
|
||||
ignore: ignore,
|
||||
|
||||
language: language,
|
||||
fs: FS.reduceScope(parent.getContentFS(), language)
|
||||
|
||||
+1
-1
@@ -229,7 +229,7 @@ FS.prototype.listAllFiles = function(dirName, filterFn) {
|
||||
};
|
||||
|
||||
/**
|
||||
Find a file in a folder (case incensitive)
|
||||
Find a file in a folder (case insensitive)
|
||||
Return the found filename
|
||||
|
||||
@param {String} dirname
|
||||
|
||||
@@ -55,6 +55,11 @@ Parser.prototype.parsePage = function(content) {
|
||||
return Promise(page(content));
|
||||
};
|
||||
|
||||
Parser.prototype.parseInline = function(content) {
|
||||
var inline = this.get('inline');
|
||||
return Promise(inline(content));
|
||||
};
|
||||
|
||||
Parser.prototype.parseLanguages = function(content) {
|
||||
var langs = this.get('langs');
|
||||
return Promise(langs(content));
|
||||
|
||||
@@ -8,7 +8,7 @@ var parsers = require('../parsers');
|
||||
|
||||
@param {Book} book
|
||||
@param {String} filename
|
||||
@return {Promise<>}
|
||||
@return {Promise<File | Undefined>}
|
||||
*/
|
||||
function findParsableFile(book, filename) {
|
||||
var fs = book.getContentFS();
|
||||
|
||||
+11
-10
@@ -1,13 +1,14 @@
|
||||
|
||||
module.exports = {
|
||||
parseBook: require('./parseBook'),
|
||||
parseSummary: require('./parseSummary'),
|
||||
parseGlossary: require('./parseGlossary'),
|
||||
parseReadme: require('./parseReadme'),
|
||||
parseConfig: require('./parseConfig'),
|
||||
parsePagesList: require('./parsePagesList'),
|
||||
parseIgnore: require('./parseIgnore'),
|
||||
listAssets: require('./listAssets'),
|
||||
parseLanguages: require('./parseLanguages'),
|
||||
parsePage: require('./parsePage')
|
||||
parseBook: require('./parseBook'),
|
||||
parseSummary: require('./parseSummary'),
|
||||
parseGlossary: require('./parseGlossary'),
|
||||
parseReadme: require('./parseReadme'),
|
||||
parseConfig: require('./parseConfig'),
|
||||
parsePagesList: require('./parsePagesList'),
|
||||
parseIgnore: require('./parseIgnore'),
|
||||
listAssets: require('./listAssets'),
|
||||
parseLanguages: require('./parseLanguages'),
|
||||
parsePage: require('./parsePage'),
|
||||
lookupStructureFile: require('./lookupStructureFile')
|
||||
};
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
var findParsableFile = require('./findParsableFile');
|
||||
|
||||
/**
|
||||
Lookup a structure file (ex: SUMMARY.md, GLOSSARY.md) in a book. Uses
|
||||
book's config to find it.
|
||||
|
||||
@param {Book} book
|
||||
@param {String} type: one of ["glossary", "readme", "summary", "langs"]
|
||||
@return {Promise<File>} The path of the file found, relative
|
||||
to the book content root.
|
||||
*/
|
||||
function lookupStructureFile(book, type) {
|
||||
var config = book.getConfig();
|
||||
|
||||
var fileToSearch = config.getValue(['structure', type]);
|
||||
|
||||
return findParsableFile(book, fileToSearch);
|
||||
}
|
||||
|
||||
module.exports = lookupStructureFile;
|
||||
+18
-16
@@ -1,6 +1,23 @@
|
||||
var Promise = require('../utils/promise');
|
||||
var IGNORE_FILES = require('../constants/ignoreFiles');
|
||||
|
||||
var DEFAULT_IGNORES = [
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'_book',
|
||||
|
||||
// Ignore files in the templates folder
|
||||
'_layouts'
|
||||
];
|
||||
|
||||
/**
|
||||
Parse ignore files
|
||||
|
||||
@@ -15,22 +32,7 @@ function parseIgnore(book) {
|
||||
var fs = book.getFS();
|
||||
var ignore = book.getIgnore();
|
||||
|
||||
ignore = ignore.add([
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'_book',
|
||||
|
||||
// Ignore files in the templates folder
|
||||
'_layouts'
|
||||
]);
|
||||
ignore = ignore.add(DEFAULT_IGNORES);
|
||||
|
||||
return Promise.serie(IGNORE_FILES, function(filename) {
|
||||
return fs.readAsString(filename)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var findParsableFile = require('./findParsableFile');
|
||||
var Promise = require('../utils/promise');
|
||||
var error = require('../utils/error');
|
||||
var lookupStructureFile = require('./lookupStructureFile');
|
||||
|
||||
/**
|
||||
Parse a ParsableFile using a specific method
|
||||
@@ -55,11 +55,8 @@ function parseFile(fs, file, type) {
|
||||
*/
|
||||
function parseStructureFile(book, type) {
|
||||
var fs = book.getContentFS();
|
||||
var config = book.getConfig();
|
||||
|
||||
var fileToSearch = config.getValue(['structure', type]);
|
||||
|
||||
return findParsableFile(book, fileToSearch)
|
||||
return lookupStructureFile(book, type)
|
||||
.then(function(file) {
|
||||
if (!file) return [undefined, undefined];
|
||||
|
||||
|
||||
@@ -8,7 +8,16 @@ function normalizePath(filename) {
|
||||
|
||||
// Return true if file path is inside a folder
|
||||
function isInRoot(root, filename) {
|
||||
root = path.normalize(root);
|
||||
filename = path.normalize(filename);
|
||||
|
||||
if (root === '.') {
|
||||
return true;
|
||||
}
|
||||
if (root[root.length - 1] != path.sep) {
|
||||
root = root + path.sep;
|
||||
}
|
||||
|
||||
return (filename.substr(0, root.length) === root);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "3.0.0-pre.15",
|
||||
"version": "3.0.0",
|
||||
"homepage": "https://www.gitbook.com",
|
||||
"description": "Library and cmd utility to generate GitBooks",
|
||||
"main": "lib/index.js",
|
||||
@@ -8,7 +8,7 @@
|
||||
"dependencies": {
|
||||
"bash-color": "0.0.4",
|
||||
"cheerio": "0.20.0",
|
||||
"chokidar": "1.4.3",
|
||||
"chokidar": "1.5.0",
|
||||
"cp": "0.2.0",
|
||||
"cpr": "1.1.1",
|
||||
"crc": "3.4.0",
|
||||
@@ -20,7 +20,7 @@
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"extend": "^3.0.0",
|
||||
"fresh-require": "1.0.3",
|
||||
"front-matter": "2.0.7",
|
||||
"front-matter": "2.0.8",
|
||||
"gitbook-asciidoc": "1.1.4",
|
||||
"gitbook-markdown": "1.2.3",
|
||||
"gitbook-plugin-fontsettings": "1.0.3",
|
||||
@@ -29,20 +29,20 @@
|
||||
"gitbook-plugin-lunr": "1.1.0",
|
||||
"gitbook-plugin-search": "2.2.1",
|
||||
"gitbook-plugin-sharing": "1.0.2",
|
||||
"gitbook-plugin-theme-default": "1.0.0",
|
||||
"gitbook-plugin-theme-default": "1.0.1",
|
||||
"github-slugid": "1.0.1",
|
||||
"graceful-fs": "4.1.3",
|
||||
"graceful-fs": "4.1.4",
|
||||
"i18n-t": "1.0.0",
|
||||
"ignore": "3.1.2",
|
||||
"immutable": "^3.8.1",
|
||||
"is": "^3.1.0",
|
||||
"json-schema-defaults": "0.1.1",
|
||||
"jsonschema": "1.1.0",
|
||||
"juice": "1.10.0",
|
||||
"juice": "1.11.0",
|
||||
"merge-defaults": "0.2.1",
|
||||
"mkdirp": "0.5.1",
|
||||
"moment": "2.13.0",
|
||||
"npm": "3.8.8",
|
||||
"npm": "3.9.2",
|
||||
"npmi": "2.0.1",
|
||||
"nunjucks": "2.4.2",
|
||||
"nunjucks-do": "1.0.0",
|
||||
@@ -61,13 +61,13 @@
|
||||
"urijs": "1.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "2.9.0",
|
||||
"eslint": "2.10.2",
|
||||
"expect": "^1.20.1",
|
||||
"mocha": "^2.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"test": "./node_modules/.bin/mocha ./testing/setup.js './lib/**/*/__tests__/*.js' --bail --reporter=list --timeout=10000"
|
||||
"test": "./node_modules/.bin/mocha ./testing/setup.js \"./lib/**/*/__tests__/*.js\" --bail --reporter=list --timeout=10000"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user