Compare commits

..

34 Commits

Author SHA1 Message Date
Samy Pessé 35f0581c17 Bump version to 3.0.0-pre.4 2016-03-07 11:16:43 +01:00
Samy Pessé c79f02fe48 Add sitemap plugin for docs 2016-03-07 11:16:27 +01:00
Samy Pessé ec028a1c0d Add deprecated methods isSubBook and contentPath 2016-03-07 11:16:13 +01:00
Samy Pessé e3155dd13a Update plugin-search@1.2.0 2016-03-07 11:00:16 +01:00
Samy Pessé b61254dda6 Add more deprecated api 2016-03-07 11:00:01 +01:00
Samy Pessé b4bdf97cfe Fix linting errors 2016-03-07 10:40:25 +01:00
Samy Pessé bf98984012 Add link to slack 2016-03-07 10:28:44 +01:00
Samy Pessé 77258cbbc9 Improve intro for doc 2016-03-07 10:27:31 +01:00
Samy Pessé 4150455c3e Improve docs 2016-03-07 10:10:38 +01:00
Samy Pessé 008aacb5c2 Fix log when installing plugins 2016-03-07 09:41:59 +01:00
Samy Pessé d12d6a6a46 Fix deprecated method root for send module 2016-03-07 09:41:05 +01:00
Samy Pessé ef7594b8f7 Remove section about autocover 2016-03-07 09:38:56 +01:00
Soreine 6a73217740 Adds section for covers 2016-03-06 09:08:48 +01:00
Samy Pesse 47c44fca89 Add changelog for master 2016-03-05 22:39:11 +01:00
Samy Pesse 6fa63a5c35 Fix #1172: Fix second argument for ebook generation 2016-03-05 22:37:25 +01:00
Samy Pessé 29533908c2 Merge pull request #1168 from GitbookIO/enhancement/doc
v3 doc review
2016-03-05 15:14:17 +01:00
Soreine 74a1e9dee2 Corrects paths. And reformulate associated FAQ 2016-03-03 16:39:18 +01:00
Soreine b3662e07c1 End of review 2016-03-03 16:39:18 +01:00
Soreine 200e0c58c9 More precise git url ? 2016-03-03 16:39:17 +01:00
Soreine e67286c51d Reviewing, first part 2016-03-03 16:39:17 +01:00
Soreine 603622e337 Update plugin-highlight version to 2.0.0 2016-03-03 16:38:09 +01:00
Samy Pessé 5c2a435a25 Update everything (npm, etc) 2016-03-02 11:22:24 +01:00
Samy Pessé 4afcd722ae Fix page description tests 2016-03-02 11:22:12 +01:00
Samy Pessé 21d6964230 Extend "page" with frontmatter attributes 2016-03-02 11:11:39 +01:00
Samy Pessé 4499ccc501 Explicitly use current version as gitbook version to build 2016-03-02 10:01:32 +01:00
Samy Pessé abbca568d1 Bump version to 3.0.0-pre.3 2016-03-02 09:29:30 +01:00
Samy Pesse 40e49d0ac9 Change json format version to follow major version of gitbook 2016-03-01 22:29:09 +01:00
Samy Pessé 8d9a0a91f0 Add test for plugin installation from github 2016-03-01 16:51:47 +01:00
Samy Pessé 15640dfdf0 Add lint to jsonlint 2016-03-01 16:31:29 +01:00
Samy Pesse 2f5dde5d2f Fix links in documentation 2016-02-29 22:00:55 +01:00
Samy Pesse a9a8a04bca Tweaks in documentation 2016-02-29 21:59:05 +01:00
Samy Pesse c08e5ce62c Improve structure of doc 2016-02-29 21:50:48 +01:00
Samy Pessé ec353e179d Remove .gitbook and add "root" option 2016-02-29 17:35:12 +01:00
Samy Pessé 496f253e69 Don't copy _layouts to output 2016-02-29 10:43:53 +01:00
51 changed files with 518 additions and 302 deletions
-1
View File
@@ -1 +0,0 @@
./docs
+1 -1
View File
@@ -28,7 +28,7 @@ build/Release
*.swp
# Output of documentation
docs/_book
_book
book.pdf
book.epub
+1 -1
View File
@@ -13,7 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Markdown parser is now using CommonMark
- Root folder for the book can be specified in a `.gitbook` file
- Multi-lingual books share assets folder
- YAML front matter is parsed and page's description can be specified in it
- YAML front matter is parsed and can extend page's properties
- Fix `uk` translation
## 2.6.7
+24
View File
@@ -0,0 +1,24 @@
var pkg = require('./package.json');
module.exports = {
// Documentation for GitBook is stored under "docs"
root: './docs',
title: 'GitBook Documentation',
// Enforce use of GitBook v3
gitbook: pkg.version,
// Use the "official" theme
plugins: ['theme-official', 'sitemap'],
theme: 'official',
variables: {
version: pkg.version
},
pluginsConfig: {
sitemap: {
hostname: 'https://docs.gitbook.com'
}
}
};
+8 -4
View File
@@ -1,10 +1,12 @@
# GitBook Format Documentation
> This documentation is for GitBook version **{{ book.version }}**
This document aims to be a comprehensive guide to GitBook. It contains the full documentation for version **{{ book.version }}**. Help for GitBook.com specific questions can be found at [help.gitbook.com](https://help.gitbook.com).
GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc). Here is an example: [Learn Javascript](https://www.gitbook.com/book/GitBookIO/javascript). This documentation has been generated using GitBook.
### What is GitBook?
GitBook can output your content as a website ([customizable](themes.md) and [extensibles](plugins.md)) or as an ebook (PDF, ePub or Mobi).
GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc). . This documentation has been generated using GitBook.
GitBook can output your content as a website ([customizable](themes/README.md) and [extensibles](plugins/README.md)) or as an ebook (PDF, ePub or Mobi).
[GitBook.com](https://www.gitbook.com) is the online platform to create and host books built using the GitBook format. It offers hosting, collaboration features and an [easy-to-use editor](https://www.gitbook.com/editor).
@@ -12,9 +14,11 @@ GitBook can output your content as a website ([customizable](themes.md) and [ext
We're always happy to help out with your books or any other questions you might have. You can ask a question on the following contact form at [gitbook.com/contact](https://www.gitbook.com/contact) or signal an issue on [GitHub](https://github.com/GitbookIO/gitbook).
Check out the [GitBook Community Slack Channel](https://slack.gitbook.com), Stay updated by following [@GitBookIO](https://twitter.com/GitBookIO) on Twitter or [GitBook](https://www.facebook.com/gitbookcom) on Facebook.
### FAQ
There are questions that are asked quite often, [check this out before creating an issue](faq.md).
Some questions are frequently asked. If you have a problem you should [check this out](faq.md) first.
### Contribute to this documentation
+10 -9
View File
@@ -9,25 +9,26 @@
* [Directory structure](structure.md)
* [Pages and Summary](pages.md)
* [Configuration](config.md)
* [Glossary](lexicon.md)
* [Multi-Lingual](languages.md)
* [Configuration](config.md)
* [AsciiDoc](asciidoc.md)
### Miscellaneous
* [Templating](templating.md)
* [Content References](conrefs.md)
* [Variables](variables.md)
### Customization
* [Plugins](plugins.md)
* [Theming](themes.md)
* [Cover](cover.md)
* [Templating](templating/README.md)
* [Content References](templating/conrefs.md)
* [Variables](templating/variables.md)
* [Plugins](plugins/README.md)
* [Create a plugin](plugins/create.md)
* [Test your plugin](plugins/testing.md)
* [Theming](themes/README.md)
--
* [FAQ](faq.md)
* [Examples](examples.md)
* [Release notes](https://github.com/GitbookIO/gitbook/blob/master/CHANGES.md)
+3
View File
@@ -4,6 +4,9 @@
<a href="https://github.com/GitbookIO/gitbook/blob/master/docs/{{ file.path }}" target="_blank" class="btn btn-link pull-right hidden-xs">
<i class="octicon octicon-mark-github"></i> Edit on GitHub
</a>
<a href="{{ "faq.md"|resolveFile }}" class="btn btn-link pull-right hidden-xs">
F.A.Q
</a>
<a href="https://github.com/GitbookIO/gitbook/blob/master/CHANGES.md" target="_blank" class="btn btn-link pull-right hidden-xs">
{{ book.version }}
</a>
+10 -5
View File
@@ -8,11 +8,11 @@ Just like for markdown, GitBook is using some special files to extract structure
### README.adoc
This is the main entry of your book: the introduction. This file is **non optional**.
This is the main entry of your book: the introduction. This file is **required**.
### SUMMARY.adoc
This file defines the list of chapters and subchapters. Just like [for markdown](./pages.md), the `SUMMARY.adoc`'s format is simply a list of links, the name of the link is used as the chapter's name, and the target is a path to that chapter's file.
This file defines the list of chapters and subchapters. Just like in Markdown, the `SUMMARY.adoc`'s format is simply a list of links, the name of the link is used as the chapter's name, and the target is a path to that chapter's file.
Subchapters are defined simply by adding a nested list to a parent chapter.
@@ -51,10 +51,15 @@ This file is used to define terms. [See the glossary section](./lexicon.md).
= Glossary
== Magic
Sufficiently advanced technology, beyond the understanding of the observer producing a sense of wonder.
Sufficiently advanced technology, beyond the understanding of the
observer producing a sense of wonder.
== PHP
An atrocious language, invented for the sole purpose of inflicting pain and suffering amongst the programming wizards of this world.
```
A popular web programming language, used by many large websites such
as Facebook. Rasmus Lerdorf originally created PHP in 1994 to power
his personal homepage (PHP originally stood for "Personal Home Page"
but now stands for "PHP: Hypertext Preprocessor"). ```
-11
View File
@@ -1,11 +0,0 @@
var pkg = require('../package.json');
module.exports = {
title: 'GitBook Documentation',
plugins: ['theme-official'],
theme: 'official',
variables: {
version: pkg.version
}
};
+23 -12
View File
@@ -1,20 +1,36 @@
# Configuration
GitBook allows you to customize your book using a flexible configuration. These options are specified in a `book.json` file.
GitBook allows you to customize your book using a flexible configuration. These options are specified in a `book.json` file. For authors unfamiliar with the JSON syntax, you can validate the syntax using tools such as [JSONlint](http://jsonlint.com).
### Configuration Settings
### General Settings
| Variable | Description |
| -------- | ----------- |
| `root` | Path to the root folder containing all the book's files, except `book.json`|
| `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. |
| `isbn` | ISBN of the book |
| `language` | ISO code of the book's language, default value is `en` |
| `direction` | `rtl` or `ltr`, default value depends on the value of `language` |
| `gitbook` | [SemVer](http://semver.org) condition to validate which GitBook version should be used |
| `plugins` | List of plugins to load, See [the plugins section](plugins.md) for more details |
| `pluginsConfig` |Configuration for plugins, See [the plugins section](plugins.md) for more details |
| `language` | [ISO code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) of the book's language, default value is `en` |
| `direction` | Text's direction. Can be `rtl` or `ltr`, the default value depends on the value of `language` |
| `gitbook` | Version of GitBook that should be used. Uses the [SemVer](http://semver.org) specification and accepts conditions like `">= 3.0.0"` |
### Plugins
Plugins and their configurations are specified in the `book.json`. See [the plugins section](plugins/README.md) for more details.
| Variable | Description |
| -------- | ----------- |
| `plugins` | List of plugins to load |
| `pluginsConfig` |Configuration for plugins |
### Theme
Since version 3.0.0, GitBook can use themes. See [the theming section](themes/README.md) for more details.
| Variable | Description |
| -------- | ----------- |
| `theme` | The theme to use for the book |
### PDF Options
@@ -30,8 +46,3 @@ PDF Output can be customized using a set of options in the `book.json`:
| `pdf.margin.bottom` | Bottom margin (default is `56`) |
| `pdf.margin.right` | Right margin (default is `62`) |
| `pdf.margin.left` | Left margin (default is `62`) |
### Plugins
Plugins and their configurations are specified in the `book.json`. See [the plugins section](plugins.md) for more details.
+21
View File
@@ -0,0 +1,21 @@
# Cover
Covers are used for all the ebook formats, and to make books more elegant on GitBook.com.
To provide a cover, place a **cover.jpg** file at the root directory of your book. Adding a **cover_small.jpg** will specify a smaller version of the cover. The cover should be a **JPEG** file.
### Best Sizes
| | Big | Small |
|:-------------------:|:-----------:|:-----------------:|
| **File** | `cover.jpg` | `cover_small.jpg` |
| **Size(in pixels)** | 1800x2360 | 200x262 |
### Guidelines
A good cover respects the following guidelines:
* No border
* Clearly visible book title
* Any important text should be visible in the small version
+3 -3
View File
@@ -4,7 +4,7 @@ description: Real world examples of content published using GitBook.
# Examples
More than 50,000 books have benn published on [GitBook.com](https://www.gitbook.com/explore).
More than 50,000 books have been published on [GitBook.com](https://www.gitbook.com/explore).
### Books
@@ -17,11 +17,11 @@ More than 50,000 books have benn published on [GitBook.com](https://www.gitbook.
### Research Papers
- [TowCenter Collection](https://www.gitbook.com/@towcenter) by [Columbia Journalism School]()
- [TowCenter Collection](https://www.gitbook.com/@towcenter) by [Columbia Journalism School](http://www.journalism.columbia.edu/)
- [Block Relaxation Algorithms in Statistics](https://www.gitbook.com/@jandeleeuw) by Jan de Leeuw
### Documentation
- [DuckDuckHack Documentation](http://docs.duckduckhack.com) by DuckDuckGo
- [DuckDuckHack Documentation](http://docs.duckduckhack.com) by [DuckDuckGo](https://duckduckgo.com/about)
- This documentation
+3 -3
View File
@@ -12,7 +12,7 @@ Any text editor should work! But we advise using the [GitBook Editor](https://ww
#### Should I use an `.html` or `.md` extensions in my links?
You should always use `.md` extensions for your relative links, GitBook will automatically replace these links by the right value when the pointing file is referenced in the Table of Contents.
You should always use paths and the `.md` extensions when linking to your files, GitBook will automatically replace these paths by the appropriate link when the pointing file is referenced in the Table of Contents.
#### Can I create a GitBook in a sub-directory of my repository?
@@ -26,8 +26,8 @@ GitBook supports math equations and TeX thanks to plugins. There are currently 2
#### Can I customize/theme the output?
Yes, both the website and ebook outputs can be customized using [themes](themes.md).
Yes, both the website and ebook outputs can be customized using [themes](themes/README.md).
#### Can I add interactive content (videos, etc)?
GitBook is very [extensible](plugins.md). You can use [existing plugins](https://plugins.gitbook.com) or create your own!
GitBook is very [extensible](plugins/README.md). You can use [existing plugins](https://plugins.gitbook.com) or create your own!
+3 -1
View File
@@ -3,6 +3,8 @@
GitBook supports building books written in multiple languages. Each language should be a sub-directory following the normal GitBook format, and a file named `LANGS.md` should be present at the root of the repository with the following format:
```markdown
# Languages
* [English](en/)
* [French](fr/)
* [Español](es/)
@@ -12,4 +14,4 @@ GitBook supports building books written in multiple languages. Each language sho
When a language book (ex: `en`) has a `book.json`, its configuration will extend the main configuration.
The only exception is plugins, plugins are specify globally relative to the book, and language specific plugins can not be specified.
The only exception is plugins, plugins are specified globally, and language specific plugins cannot be specified.
+4 -3
View File
@@ -1,6 +1,6 @@
# Glossary
Allows you to specify terms and their respective definitions to be displayed as annotations. Based on those terms, gitbook will automatically build an index and highlight those terms in pages.
Allows you to specify terms and their respective definitions to be displayed as annotations. Based on those terms, GitBook will automatically build an index and highlight those terms in pages.
The `GLOSSARY.md` format is very simple :
@@ -9,5 +9,6 @@ The `GLOSSARY.md` format is very simple :
Definition for this term
# Another term
With it's definition, this can contain bold text and all other kinds of inline markup ...
```
With it's definition, this can contain bold text
and all other kinds of inline markup ...
```
+37 -7
View File
@@ -1,12 +1,12 @@
# Pages and Summary
GitBook uses a `SUMMARY.md` file to define the structure of chapters and subchapters of the book. The `SUMMARY.md` file is used to generate the book's table of contents.
### Summary
The `SUMMARY.md`'s format is simply a list of links, the title of the link is used as the chapter's title, and the target is a path to that chapter's file.
GitBook uses a `SUMMARY.md` file to define the structure of chapters and subchapters of the book. The `SUMMARY.md` file is used to generate the book's table of contents.
Subchapters are defined simply by adding a nested list to a parent chapter.
The format of `SUMMARY.md` is just a list of links. The link's title is used as the chapter's title, and the link's target is a path to that chapter's file.
Adding a nested list to a parent chapter will create subchapters.
##### Simple example
@@ -21,23 +21,50 @@ Subchapters are defined simply by adding a nested list to a parent chapter.
* [Better tools for authors](part2/better_tools.md)
```
Each chapter has a dedicated page (`part#/README.md`) and is split into subchapters.
##### Example with subchapters split into parts
```markdown
# Summary
### Part 1
### Part I
* [Writing is nice](part1/writing.md)
* [GitBook is nice](part1/gitbook.md)
### Part 2
### Part II
* [We love feedback](part2/feedback_please.md)
* [Better tools for authors](part2/better_tools.md)
```
### Front Matter
Here, parts are just groups of chapters and do not have dedicated pages, but will show in the navigation for example.
### Pages
#### Markdown syntax
Most of the files for GitBook use the Markdown syntax by default. GitBook infers your pages's structure from it. The syntax used is similar to the [GitHub Flavored Markdown syntax](https://guides.github.com/features/mastering-markdown/). One can also opt for the [AsciiDoc syntax](asciidoc.md).
##### Example of a chapter file
``` markdown
# Title of the chapter
This is a great introduction.
## Section 1
Markdown will dictates _most_ of your **book's structure**
## Section 2
...
```
#### Front Matter
Pages can contain an optional front matter. It can be used to define the page's description. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines. Here is a basic example:
@@ -47,4 +74,7 @@ description: This is a short description of my page
---
# The content of my page
...
```
The front matter can define variables of your own, they will be added to the [page variable](templating/variables.md) so you can use them in your templating.
+3 -1
View File
@@ -19,8 +19,10 @@ Once you find a plugin that you want to install, you need to add it to your `boo
You can also specify a specific version using: `"myPlugin@0.3.1"`. By default GitBook will resolve the latest version of the plugin compatbile with the current GitBook version.
### GitBook.com
Plugins are automatically installed on [GitBook.com](https://www.gitbook.com). Locally, run `gitbook install` to install and prepare all plugins for your books.
### Configuring plugins
PLugins specific configurations are stored in `pluginsConfig`. You have to refer to the documentation of the plugin itself for details about the available options.
Plugins specific configurations are stored in `pluginsConfig`. You have to refer to the documentation of the plugin itself for details about the available options.
+63
View File
@@ -0,0 +1,63 @@
# Create and publish a plugin
A GitBook plugin is a node package published on NPM that follow a defined convention.
## Structure
#### package.json
The `package.json` is a manifest format for describing **Node.js modules**. GitBook plugins are built on top of Node modules. It declares dependencies, version, ownership, and other information required to run a plugin in GitBook. This document describes the schema in detail.
```
{
"name": "gitbook-plugin-mytest",
"version": "0.0.1",
"description": "This is my first GitBook plugin",
"engines": {
"gitbook": ">1.x.x"
}
}
```
You can learn more about `package.json` from the [NPM documentation](https://docs.npmjs.com/files/package.json).
The **package name** must begin with `gitbook-plugin-` and the **package engines** should contains `gitbook`.
#### index.js
The `index.js` is main entry point of your plugin runtime:
```js
module.exports = {
// Map of hooks
hooks: {},
// Map of new blocks
blocks: {},
// Map of new filters
filters: {}
};
```
## Publish your plugin
GitBook plugins can be published on [NPM](https://www.npmjs.com).
To publish a new plugin, you need to create an account on [npmjs.com](https://www.npmjs.com) then publish it from the command line:
```
$ npm publish
```
## Private plugins
Private plugins can be hosted on GitHub and included using `git` urls:
```
{
"plugins": [
"myplugin@git+https://github.com/MyCompany/mygitbookplugin.git#1.0.0"
]
}
```
View File
+22
View File
@@ -0,0 +1,22 @@
# Testing your plugin
### Testing your plugin locally
Testing your plugin on your book before plushing it is possible using [npm link](https://docs.npmjs.com/cli/link).
In the plugin's folder, run:
```
$ npm link
```
The nin your book's folder:
```
$ npm link gitbook-plugin-<plugin's name>
```
### Unit testing on Travis
[gitbook-tester](https://github.com/todvora/gitbook-tester) makes it easy to write **Node.js/Mocha** unit tests for your plugins. Using [Travis.org](https://travis.org), tests can be run on each commits/tags.
+5 -5
View File
@@ -4,7 +4,7 @@ Getting GitBook installed and ready-to-go should only take a few minutes.
### GitBook.com
[GitBook.com](https://www.gitbook.com) is an easy to use solution to write, publish and host books. It's best and easier solution for publishing your content and collaborate on it.
[GitBook.com](https://www.gitbook.com) is an easy to use solution to write, publish and host books. It is the easiest solution for publishing your content and collaborating on it.
It integrates well with the [GitBook Editor](https://www.gitbook.com/editor).
@@ -12,7 +12,7 @@ It integrates well with the [GitBook Editor](https://www.gitbook.com/editor).
##### Requirements
Installing GitBook is easy and straight-forward, but there are a few requirements youll need to make sure your system has before you start.
Installing GitBook is easy and straightforward. Your system just needs to meet these two requirements:
* NodeJS (v4.0.0 and above are adviced)
* Windows, Linux, Unix, or Mac OS X
@@ -25,7 +25,7 @@ The best way to install GitBook is via **NPM**. At the terminal prompt, simply r
$ npm install gitbook-cli -g
```
`gitbook-cli` is an utility to install and use multiple versions of GitBook on the same system. It will automatically install the required version to build a book.
`gitbook-cli` is an utility to install and use multiple versions of GitBook on the same system. It will automatically install the required version of GitBook to build a book.
##### Create a book
@@ -43,7 +43,7 @@ Preview and serve your book using:
$ gitbook serve
```
or build the static website using:
Or build the static website using:
```
$ gitbook build
@@ -51,7 +51,7 @@ $ gitbook build
##### Install pre-releases
`gitbook-cli` makes it easy to install and test other versions of GitBook with your book:
`gitbook-cli` makes it easy to download and install other versions of GitBook to test with your book:
```
$ gitbook fetch beta
+15 -11
View File
@@ -1,6 +1,8 @@
# Directory structure
# Directory Structure
GitBook uses a very simple and obvious directory sttructure:
GitBook uses a simple directory structure. All Markdown/Asciidoc files listed in the [SUMMARY](pages.md) will be transformed as HTML. Multi-Lingual books have a slightly [different structure](languages.md).
A basic GitBook usually looks something like this:
```
.
@@ -21,19 +23,19 @@ An overview of what each of these does:
| -------- | ----------- |
| `book.json` | Stores [configuration](config.md) data (__optional__) |
| `README.md` | Preface / Introduction for your book (**required**) |
| `SUMMARY.md` | Table of Contents |
| `SUMMARY.md` | Table of Contents (See [Pages](pages.md)) (__optional__) |
| `GLOSSARY.md` | Lexicon / List of terms to annotate (See [Glossary](lexicon.md)) (__optional__) |
### Static files and Images
A static file is a file that is not listed in the `SUMMARY.md`. All static files, not [ignored](#ignore), are copied to the output.
A static file is a file that is not listed in the `SUMMARY.md`. All static files, unless [ignored](#ignore), are copied to the output.
### Ignoring files & folders {#ignore}
GitBook will read the `.gitignore`, `.bookignore` and `.ignore` files to get a list of files and folders to skip.
The format inside those files, follows the same convention as `.gitignore`:
```markdown
```
# This is a comment
# Ignore the file test.md
@@ -43,20 +45,22 @@ test.md
bin/*
```
### Project documentation / Sub-directory {#subdirectory}
### Project integration with subdirectory {#subdirectory}
For project documentaiton, it sometimes better to use a diretcory (like `docs/`) to store the prject's documentation. You can use a `.gitbook` file to indicate to GitBook in which folder the book is stored:
For software projects, you can use a subdirectory (like `docs/`) to store the book for the project's documentation. You can configure the [`root` option](config.md) to indicate the folder where GitBook can find the book's files:
```
.
├── .gitbook
├── book.json
└── docs/
├── README.md
└── SUMMARY.md
```
With `.gitbook` containing:
With `book.json` containing:
```
./docs/
{
"root": "./docs"
}
```
@@ -1,18 +1,18 @@
# Templating
GitBook uses the Nunjucks templating language to process pages and theme's templates.
GitBook uses the [Nunjucks templating language](https://mozilla.github.io/nunjucks/) to process pages and theme's templates.
The Nunjucks syntax is very similar to **Jinja2** or **Liquid**.
The Nunjucks syntax is very similar to **Jinja2** or **Liquid**. Its syntax uses surrounding braces `{ }` to mark content that needs to be processed.
### Variables
A variable looks up a value from the template context. If you wanted to simply display a variable, you would do:
A variable looks up a value from the template context. If you wanted to simply display a variable, you would use the `{{ variable }}` syntax. For example :
```twig
{{ username }}
My name is {{ name }}, nice to meet you
```
This looks up username from the context and displays it. Variable names can have dots in them which lookup properties, just like javascript. You can also use the square bracket syntax.
This looks up username from the context and displays it. Variable names can have dots in them which lookup properties, just like JavaScript. You can also use the square bracket syntax.
```twig
{{ foo.bar }}
@@ -21,7 +21,7 @@ This looks up username from the context and displays it. Variable names can have
If a value is undefined, nothing is displayed. The following all output nothing if foo is undefined: `{{ foo }}`, `{{ foo.bar }}`, `{{ foo.bar.baz }}`.
GitBook provides a set of [context variables](variables.md).
GitBook provides a set of [predefined variables](variables.md) from the context.
### Filters
@@ -39,7 +39,7 @@ The third example shows how you can chain filters. It would display "Bar", by fi
##### if
`if` tests a condition and lets you selectively display content. It behaves exactly as javascript's if behaves.
`if` tests a condition and lets you selectively display content. It behaves exactly as JavaScript's `if` behaves.
```twig
{% if variable %}
@@ -49,7 +49,7 @@ The third example shows how you can chain filters. It would display "Bar", by fi
If variable is defined and evaluates to true, "It is true" will be displayed. Otherwise, nothing will be.
You can specify alternate conditions with elif and else:
You can specify alternate conditions with `elif` and `else`:
```twig
{% if hungry %}
@@ -86,5 +86,4 @@ Current version is {{ softwareVersion }}.
##### include and block
Inclusion and inheritance is detailled in the [ConRefs](conrefs.md) section.
Inclusion and inheritance is detailled in the [Content References](conrefs.md) section.
@@ -1,10 +1,10 @@
# Content References
Content referencing (conref) is a convenient mechanism for reuse of content from other files or books.
Content referencing (conref) is a convenient mechanism to reuse content from other files or books.
### Importing local files
Importing an other file's content is really easy using the `include` tag:
Importing an other file's content is easy using the `include` tag:
```
{% include "./test.md" %}
@@ -21,7 +21,7 @@ GitBook can also resolve the include path by using git:
The format of git url is:
```
git+https://user@hostname/project/blah.git/file#commit-ish
git+https://user@hostname/owner/project.git/file#commit-ish
```
The real git url part should finish with `.git`, the filename to import is extracted after the `.git` till the fragment of the url.
@@ -42,7 +42,7 @@ Template inheritance is a way to make it easy to reuse templates. When writing a
{% endblock %}
```
In the file `mypage.md`, you should specify the blocks that can be extent:
In the file `mypage.md`, you should specify the blocks that can be extended:
```
{% block pageContent %}
@@ -6,7 +6,7 @@ The following is a reference of the available data during book's parsing and the
| Variable | Description |
| -------- | ----------- |
| `book` | Bookwide information + configuration settings from `book.json`. See below for details. |
| `book` | Book-wide information + configuration settings from `book.json`. See below for details. |
| `gitbook` | GitBook specific information |
| `page` | Current page specific information |
| `file` | File associated with the current page specific information |
@@ -25,7 +25,7 @@ The following is a reference of the available data during book's parsing and the
| Variable | Description |
| -------- | ----------- |
| `gitbook.time` | The current time (when you run the `gitbook` command). |
| `gitbook.time` | The current time (when you run the `gitbook` command) . |
| `gitbook.version` | Version of GitBook used to generate the book |
### File Variables
@@ -33,7 +33,7 @@ The following is a reference of the available data during book's parsing and the
| Variable | Description |
| -------- | ----------- |
| `file.path` | The path to the raw page |
| `file.mtime` | Modified Time, Time when file data last modified |
| `file.mtime` | Modified Time. Last time the file was modified |
| `file.type` | The name of the parser used to compile this file (ex: `markdown`, `asciidoc`, etc) |
#### Page Variables
@@ -51,7 +51,7 @@ The following is a reference of the available data during book's parsing and the
| -------- | ----------- |
| `summary.parts` | List of sections in the Table of Contents |
Thw whole table of contents (`SUMMARY.md`) can be accessed:
The whole table of contents (`SUMMARY.md`) can be accessed:
`summary.parts[0].articles[0].title` will return the title of the first article.
+1 -1
View File
@@ -23,4 +23,4 @@ Authors can extend the templates of a theme directly from the book source (witho
### Publish a theme
Themes are published as plugins ([see related docs](plugins.md)) with a `theme-` prefix. For example the theme `awesome` will be loaded from `theme-awesome` plugin, and then from `gitbook-plugin-theme-awesome` NPM package.
Themes are published as plugins ([see related docs](../plugins/README.md)) with a `theme-` prefix. For example the theme `awesome` will be loaded from the `theme-awesome` plugin, and then from the `gitbook-plugin-theme-awesome` NPM package.
+6 -11
View File
@@ -1,6 +1,5 @@
var _ = require('lodash');
var util = require('util');
var url = require('url');
var location = require('../utils/location');
var error = require('../utils/error');
@@ -32,17 +31,13 @@ function TOCArticle(def, parent) {
// Path can be a relative path or an url, or nothing
this.ref = def.path;
if (this.ref) {
var parts = url.parse(this.ref);
if (this.ref && !this.isExternal()) {
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);
if (!this.isExternal()) {
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);
// Normalize path to remove ('./', etc)
this.path = location.normalize(this.path);
}
// Normalize path to remove ('./', etc)
this.path = location.normalize(this.path);
}
this.articles = _.map(def.articles || [], function(article) {
+35 -26
View File
@@ -100,6 +100,12 @@ function Book(opts) {
var cfg = this.config.dump();
error.deprecateField(cfg, 'book', (this.output? this.output.name : null), '"options.generator" property is deprecated, use "output.name" instead');
// options.generator
cfg.generator = this.output? this.output.name : null;
// options.output
cfg.output = this.output? this.output.root() : null;
return cfg;
}
});
@@ -123,7 +129,16 @@ Book.prototype.getContext = function() {
// Parse and prepare the configuration, fail if invalid
Book.prototype.prepareConfig = function() {
return this.config.load();
var that = this;
return this.config.load()
.then(function() {
var rootFolder = that.config.get('root');
if (!rootFolder) return;
that.originalRoot = that.root;
that.root = path.resolve(that.root, rootFolder);
});
};
// Resolve a path in the book source
@@ -344,35 +359,29 @@ Book.prototype.isInLanguageBook = function(filename) {
});
};
// Locate a book in a folder
// - Read the ".gitbook" is exists
// - Try the folder itself
// - Try a "docs" folder
Book.locate = function(fs, root) {
return fs.readAsString(path.join(root, '.gitbook'))
.then(function(content) {
return path.join(root, content);
}, function() {
// .gitbook doesn't exists, fall back to the root folder
return Promise(root);
});
};
// ----- DEPRECATED METHODS
Book.prototype.contentLink = error.deprecateMethod(function(s) {
return this.output.toURL(s);
}, '.contentLink() is deprecated, use ".output.toURL()" instead');
Book.prototype.contentPath = error.deprecateMethod(function(s) {
return this.output.toURL(s);
}, '.contentPath() is deprecated, use ".output.toURL()" instead');
Book.prototype.isSubBook = error.deprecateMethod(function() {
return this.isLanguageBook();
}, '.isSubBook() is deprecated, use ".isLanguageBook()" instead');
// Locate and setup a book
Book.setup = function(fs, root, opts) {
return Book.locate(fs, root)
.then(function(_root) {
return new Book(_.extend(opts || {}, {
root: _root,
fs: fs
}));
});
};
// Initialize a book
Book.init = function(fs, root, opts) {
return Book.setup(fs, root, opts)
.then(initBook);
var book = new Book(_.extend(opts || {}, {
root: root,
fs: fs
}));
return initBook(book);
};
+6 -5
View File
@@ -42,12 +42,13 @@ var FORMATS = {
function bookCmd(fn) {
return function(args, kwargs) {
var input = path.resolve(args[0] || process.cwd());
return Book.setup(nodeFS, input, {
var book = new Book({
fs: nodeFS,
root: input,
logLevel: kwargs.log
})
.then(function(book) {
return fn(book, args.slice(1), kwargs);
});
return fn(book, args.slice(1), kwargs);
};
}
@@ -80,7 +81,7 @@ function ebookCmd(format) {
return fs.tmpDir()
.then(function(dir) {
var ext = '.'+format;
var outputFile = path.resolve(process.cwd(), args[1] || ('book' + ext));
var outputFile = path.resolve(process.cwd(), args[0] || ('book' + ext));
var output = new EBookOutput(book, {
root: dir,
format: format
+19 -19
View File
@@ -7,7 +7,6 @@ var tinylr = require('tiny-lr');
var Promise = require('../utils/promise');
var PluginsManager = require('../plugins');
var Book = require('../book');
var initBook = require('../init');
var helper = require('./helper');
var Server = require('./server');
@@ -131,26 +130,27 @@ module.exports = {
// Generate the book
.then(function() {
return Book.setup(helper.nodeFS, input, {
'logLevel': kwargs.log
})
.then(function(book) {
return book.parse()
.then(function() {
// Add livereload plugin
book.config.set('plugins',
book.config.get('plugins')
.concat([
{ name: 'livereload' }
])
);
var book = new Book({
fs: helper.nodeFS,
root: input,
logLevel: kwargs.log
});
var Out = helper.FORMATS[kwargs.format];
var output = new Out(book);
return book.parse()
.then(function() {
// Add livereload plugin
book.config.set('plugins',
book.config.get('plugins')
.concat([
{ name: 'livereload' }
])
);
return output.generate()
.thenResolve(output);
});
var Out = helper.FORMATS[kwargs.format];
var output = new Out(book);
return output.generate()
.thenResolve(output);
});
})
+3 -2
View File
@@ -64,8 +64,9 @@ Server.prototype.start = function(dir, port) {
}
// Send file
send(req, url.parse(req.url).pathname)
.root(dir)
send(req, url.parse(req.url).pathname, {
root: dir
})
.on('error', error)
.on('directory', redirect)
.pipe(res);
+3 -3
View File
@@ -4,13 +4,13 @@ module.exports = {
'title': 'GitBook Configuration',
'type': 'object',
'properties': {
'title': {
'root': {
'type': 'string',
'title': 'Title of the book, default is extracted from README'
'title': 'Path fro the root folder containing the book\'s content'
},
'title': {
'type': 'string',
'title': 'Description of the book, default is extracted from README'
'title': 'Title of the book, default is extracted from README'
},
'isbn': {
'type': 'string',
-1
View File
@@ -1,4 +1,3 @@
var _ = require('lodash');
var path = require('path');
var fs = require('./utils/fs');
+3 -2
View File
@@ -147,6 +147,7 @@ Output.prototype.prepare = function() {
'.ignore',
'.bookignore',
'node_modules',
'_layouts',
// The configuration file should not be copied in the output
this.book.config.path,
@@ -184,7 +185,7 @@ Output.prototype.onRelativeLink = function(currentPage, href) {
href = currentPage.relative(href);
// Replace .md by .html
href = this.outputUrl(href);
href = this.toURL(href);
}
return href;
@@ -262,7 +263,7 @@ Output.prototype.outputPath = function(filename, ext) {
// Filename for output
// /test/index.html -> /test/
Output.prototype.outputUrl = function(filename, ext) {
Output.prototype.toURL = function(filename, ext) {
var href = this.outputPath(filename, ext);
if (path.basename(href) == 'index.html' && this.opts.directoryIndex) {
+1 -1
View File
@@ -114,7 +114,7 @@ EbookOutput.prototype.locateCover = function() {
// Cover doesn't exist and multilingual?
if (!fs.existsSync(cover)) {
if (this.parent) return this.parent.locateCover()
if (this.parent) return this.parent.locateCover();
else return undefined;
}
+1 -1
View File
@@ -22,7 +22,7 @@ JSONOutput.prototype.onPage = function(page) {
delete json.config;
// Specify JSON output version
json.version = '2';
json.version = '3';
return that.writeFile(
page.withExtension('.json'),
+1 -1
View File
@@ -117,7 +117,7 @@ WebsiteOutput.prototype.prepare = function() {
// Transform a '.md' into a '.html' (README -> index)
that.env.addFilter('contentURL', function(s) {
return location.normalize(that.outputUrl(s));
return that.toURL(s);
});
// Relase path to an asset
+10 -10
View File
@@ -23,12 +23,13 @@ function Page(book, filename) {
this.book = book;
this.log = this.book.log;
// Map of attributes from YAML frontmatter
// Description is also extracted by default from content
this.attributes = {};
// Current content
this.content = '';
// Short description for the page
this.description = '';
// Relative path to the page
this.path = location.normalize(filename);
@@ -122,16 +123,15 @@ Page.prototype.getContext = function() {
mtime: this.mtime,
type: this.type
},
page: {
page: _.extend({}, this.attributes, {
title: article? article.title : null,
description: this.description,
next: next? next.getContext() : null,
previous: prev? prev.getContext() : null,
level: article? article.level : null,
depth: article? article.depth : 0,
content: this.content,
dir: dir
}
})
},
gitbook.getContext(),
this.book.getContext(),
@@ -165,8 +165,8 @@ Page.prototype.toHTML = function(output) {
.then(function() {
var parsed = fm(that.content);
// Extend page with the fontmatter attribute
that.description = parsed.attributes.description || '';
// Extract attributes
that.attributes = parsed.attributes;
// Keep only the body
that.update(parsed.body);
@@ -223,8 +223,8 @@ Page.prototype.toHTML = function(output) {
// Extract description from page's content if no frontmatter
onDescription: function(description) {
if (that.description) return;
that.description = description;
if (that.attributes.description) return;
that.attributes.description = description;
},
// Convert glossary entries to annotations
-1
View File
@@ -204,7 +204,6 @@ BookPlugin.prototype._getResources = function(base) {
.then(function() {
if (that._resources[base]) return that._resources[base];
base = base;
var book = that.content[base];
// Compatibility with version 1.x.x
+1 -1
View File
@@ -87,7 +87,7 @@ function installPlugin(book, plugin, version) {
throw new Error('Found no satisfactory version for plugin "' + plugin + '"');
}
book.log.info.ln('install plugin' + plugin +'" from npm ('+npnName+') with version', version);
book.log.info.ln('install plugin "' + plugin +'" from npm ('+npnName+') with version', version);
return Promise.nfcall(npmi, {
'name': npnName,
'version': version,
+1 -1
View File
@@ -202,7 +202,7 @@ TemplateEngine.prototype.addBlock = function(name, block) {
lastBlockArgs = parser.parseSignature(null, true);
parser.advanceAfterBlockEnd(lastBlockName);
}
} while (lastBlockName != block.end)
} while (lastBlockName != block.end);
parser.advanceAfterBlockEnd();
+1 -1
View File
@@ -1,6 +1,6 @@
var _ = require('lodash');
var childProcess = require('child_process');
var spawn = require("spawn-cmd").spawn;
var spawn = require('spawn-cmd').spawn;
var Promise = require('./promise');
// Execute a command
+89 -90
View File
@@ -1,93 +1,92 @@
{
"name": "gitbook",
"version": "3.0.0-pre.2",
"homepage": "https://www.gitbook.com",
"description": "Library and cmd utility to generate GitBooks",
"main": "lib/index.js",
"dependencies": {
"q": "1.0.1",
"lodash": "3.10.1",
"graceful-fs": "4.1.3",
"resolve": "0.6.3",
"mkdirp": "0.5.1",
"error": "7.0.2",
"gitbook-markdown": "1.0.3",
"gitbook-asciidoc": "1.0.2",
"gitbook-plugin-highlight": "1.0.3",
"gitbook-plugin-sharing": "1.0.1",
"gitbook-plugin-search": "1.1.0",
"gitbook-plugin-fontsettings": "1.0.2",
"gitbook-plugin-theme-default": "1.0.0-pre.4",
"nunjucks": "2.3.0",
"nunjucks-autoescape": "1.0.0",
"nunjucks-filter": "1.0.0",
"semver": "5.0.1",
"npmi": "0.1.1",
"cheerio": "0.19.0",
"gitbook-plugin-livereload": "0.0.1",
"chokidar": "~1.0.5",
"send": "0.2.0",
"tiny-lr": "0.2.1",
"tmp": "0.0.28",
"crc": "3.2.1",
"bash-color": "0.0.3",
"urijs": "1.17.0",
"request": "2.69.0",
"npm": "2.4.1",
"dom-serializer": "0.1.0",
"spawn-cmd": "0.0.2",
"escape-string-regexp": "1.0.3",
"juice": "1.9.0",
"jsonschema": "1.1.0",
"json-schema-defaults": "0.1.1",
"merge-defaults": "0.2.1",
"github-slugid": "1.0.0",
"destroy": "1.0.4",
"ignore": "2.2.19",
"deprecated": "0.0.1",
"rmdir": "1.2.0",
"cp": "0.2.0",
"cpr": "1.0.0",
"direction": "0.1.5",
"moment": "2.11.2",
"i18n-t": "1.0.0",
"front-matter": "2.0.6",
"spawn-cmd": "0.0.2"
"name": "gitbook",
"version": "3.0.0-pre.4",
"homepage": "https://www.gitbook.com",
"description": "Library and cmd utility to generate GitBooks",
"main": "lib/index.js",
"dependencies": {
"bash-color": "0.0.3",
"cheerio": "0.20.0",
"chokidar": "1.4.3",
"cp": "0.2.0",
"cpr": "1.0.0",
"crc": "3.4.0",
"deprecated": "0.0.1",
"destroy": "1.0.4",
"direction": "0.1.5",
"dom-serializer": "0.1.0",
"error": "7.0.2",
"escape-string-regexp": "1.0.5",
"eslint": "^2.2.0",
"front-matter": "2.0.6",
"gitbook-asciidoc": "1.0.2",
"gitbook-markdown": "1.0.3",
"gitbook-plugin-fontsettings": "1.0.2",
"gitbook-plugin-highlight": "2.0.0",
"gitbook-plugin-livereload": "0.0.1",
"gitbook-plugin-search": "1.2.0",
"gitbook-plugin-sharing": "1.0.1",
"gitbook-plugin-theme-default": "1.0.0-pre.4",
"github-slugid": "1.0.0",
"graceful-fs": "4.1.3",
"i18n-t": "1.0.0",
"ignore": "3.0.3",
"json-schema-defaults": "0.1.1",
"jsonschema": "1.1.0",
"juice": "1.10.0",
"lodash": "3.10.1",
"merge-defaults": "0.2.1",
"mkdirp": "0.5.1",
"moment": "2.11.2",
"npm": "3.7.5",
"npmi": "1.0.1",
"nunjucks": "2.3.0",
"nunjucks-autoescape": "1.0.1",
"q": "1.4.1",
"request": "2.69.0",
"resolve": "0.6.3",
"rmdir": "1.2.0",
"semver": "5.1.0",
"send": "0.13.1",
"spawn-cmd": "0.0.2",
"tiny-lr": "0.2.1",
"tmp": "0.0.28",
"urijs": "1.17.1"
},
"devDependencies": {
"eslint": "2.2.0",
"mocha": "2.4.5",
"should": "8.2.2"
},
"scripts": {
"test": "node_modules/.bin/mocha --reporter spec --bail --timeout 15000 ./test/all.js",
"lint": "eslint ."
},
"repository": {
"type": "git",
"url": "https://github.com/GitbookIO/gitbook.git"
},
"bin": {
"gitbook": "./bin/gitbook.js"
},
"keywords": [
"git",
"book",
"gitbook"
],
"author": "FriendCode Inc. <contact@gitbook.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/GitbookIO/gitbook/issues"
},
"contributors": [
{
"name": "Aaron O'Mullan",
"email": "aaron@gitbook.com"
},
"devDependencies": {
"eslint": "1.5.0",
"mocha": "2.4.5",
"should": "8.2.2"
},
"scripts": {
"test": "node_modules/.bin/mocha --reporter spec --bail --timeout 15000 ./test/all.js",
"lint": "eslint ."
},
"repository": {
"type": "git",
"url": "https://github.com/GitbookIO/gitbook.git"
},
"bin": {
"gitbook": "./bin/gitbook.js"
},
"keywords": [
"git",
"book",
"gitbook"
],
"author": "FriendCode Inc. <contact@gitbook.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/GitbookIO/gitbook/issues"
},
"contributors": [
{
"name": "Aaron O'Mullan",
"email": "aaron@gitbook.com"
},
{
"name": "Samy Pessé",
"email": "samy@gitbook.com"
}
]
{
"name": "Samy Pessé",
"email": "samy@gitbook.com"
}
]
}
+3 -3
View File
@@ -46,7 +46,7 @@ describe('Configuration', function() {
return mock.setupDefaultBook()
.then(function(_book) {
book = _book;
return book.config.load();
return book.prepareConfig();
});
});
@@ -64,7 +64,7 @@ describe('Configuration', function() {
})
.then(function(_book) {
book = _book;
return book.config.load();
return book.prepareConfig();
});
});
@@ -82,7 +82,7 @@ describe('Configuration', function() {
})
.then(function(_book) {
book = _book;
return book.config.load();
return book.prepareConfig();
});
});
+2 -2
View File
@@ -7,7 +7,7 @@ describe('Glossary', function() {
'GLOSSARY.md': ''
})
.then(function(book) {
return book.config.load()
return book.prepareConfig()
.then(function() {
return book.glossary.load();
@@ -27,7 +27,7 @@ describe('Glossary', function() {
})
.then(function(_book) {
book = _book;
return book.config.load();
return book.prepareConfig();
})
.then(function() {
return book.glossary.load();
+3 -3
View File
@@ -19,7 +19,7 @@ describe('Init', function() {
rootFolder.should.have.file('hello.md');
rootFolder.should.have.file('hello 2.md');
});
})
});
});
it('should create file subfolder', function() {
@@ -38,7 +38,7 @@ describe('Init', function() {
rootFolder.should.have.file('test/hello.md');
rootFolder.should.have.file('test/test2/world.md');
});
})
});
});
it('should create SUMMARY if non-existant', function() {
@@ -51,7 +51,7 @@ describe('Init', function() {
rootFolder.should.have.file('SUMMARY.md');
rootFolder.should.have.file('README.md');
});
})
});
});
});
+1 -1
View File
@@ -6,7 +6,7 @@ describe('Langs', function() {
'LANGS.md': ''
})
.then(function(book) {
return book.config.load()
return book.prepareConfig()
.then(function() {
return book.langs.load();
+17 -11
View File
@@ -1,27 +1,33 @@
var path = require('path');
var should = require('should');
var Book = require('../').Book;
var mock = require('./mock');
describe('Locate', function() {
it('should use root folder if no .gitbook', function() {
return mock.setupFS({
return mock.setupBook({
'README.md': '# Hello'
})
.then(function(root) {
return Book.locate(mock.fs, root)
.should.be.fulfilledWith(root);
.then(function(book) {
return book.prepareConfig()
.then(function() {
should(book.originalRoot).not.be.ok();
});
});
});
it('should use resolve using .gitbook', function() {
return mock.setupFS({
it('should use resolve using book.js root property', function() {
return mock.setupBook({
'README.md': '# Hello',
'.gitbook': './docs'
'docs/README.md': '# Hello Book',
'book.json': { root: './docs' }
})
.then(function(root) {
return Book.locate(mock.fs, root)
.should.be.fulfilledWith(path.resolve(root, 'docs'));
.then(function(book) {
return book.prepareConfig()
.then(function() {
should(book.originalRoot).be.ok();
book.root.should.equal(path.resolve(book.originalRoot, 'docs'));
});
});
});
+16 -6
View File
@@ -9,7 +9,8 @@ describe('Page', function() {
'README.md': ' # Hello World\n\nThis is a description',
'heading.md': '# Hello\n\n## World',
'description.md': '# This is a title\n\nThis is the short description.\n\nNot this one.',
'frontmatter.md': '---\ndescription: Hello World\n---\n\n# This is a title\n\nThis is not the description',
'frontmatter/description.md': '---\ndescription: Hello World\n---\n\n# This is a title\n\nThis is not the description',
'frontmatter/var.md': '---\ntest: Hello World\n---\n\n{{ page.test }}',
'links.md': '[link](hello.md) [link 2](variables/page/next.md) [readme](README.md)',
'links/relative.md': '[link](../hello.md) [link 2](/variables/page/next.md) [readme](../README.md)',
@@ -131,23 +132,32 @@ describe('Page', function() {
});
describe('Description', function() {
it('should extratc page description from content', function() {
it('should extract page description from content', function() {
var page = book.addPage('description.md');
return page.toHTML(output)
.then(function() {
page.description.should.equal('This is the short description.');
page.attributes.description.should.equal('This is the short description.');
});
});
});
describe('Font-Matter', function() {
it('should extratc page description from front matter', function() {
var page = book.addPage('frontmatter.md');
it('should extract page description from front matter', function() {
var page = book.addPage('frontmatter/description.md');
return page.toHTML(output)
.then(function() {
page.description.should.equal('Hello World');
page.attributes.description.should.equal('Hello World');
});
});
it('should extend page attributes with custom properties', function() {
var page = book.addPage('frontmatter/var.md');
return page.toHTML(output)
.then(function() {
page.content.should.equal('<p>Hello World</p>\n');
});
});
});
+18 -2
View File
@@ -53,7 +53,23 @@ describe('Plugins', function() {
}
})
.then(function(book) {
return book.config.load()
return book.prepareConfig()
.then(function() {
var plugins = new PluginsManager(book);
return plugins.install();
});
})
.should.be.fulfilledWith(1);
});
it('should correctly install dependencies from GitHub', function() {
return mock.setupBook({
'book.json': {
plugins: ['ga@git+https://github.com/GitbookIO/plugin-ga#master']
}
})
.then(function(book) {
return book.prepareConfig()
.then(function() {
var plugins = new PluginsManager(book);
return plugins.install();
@@ -90,7 +106,7 @@ describe('Plugins', function() {
}
})
.then(function(book2) {
return book2.config.load()
return book2.prepareConfig()
.then(function() {
var plugin = new BookPlugin(book2, 'test-config');
return plugin.load(PLUGINS_ROOT);
+1 -1
View File
@@ -6,7 +6,7 @@ describe('Readme', function() {
'README.md': ''
})
.then(function(book) {
return book.config.load()
return book.prepareConfig()
.then(function() {
return book.readme.load();