mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 07:35:16 +00:00
Compare commits
299 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3cc5c47535 | |||
| a2046814b4 | |||
| 82f814fdbd | |||
| 3842e5bf4a | |||
| f05b138fd6 | |||
| 1b87cec893 | |||
| 4a894b1e18 | |||
| c7c98009e7 | |||
| 356322e0ed | |||
| 7a47049367 | |||
| a9f473260c | |||
| d16577e8bf | |||
| 15b4053d6b | |||
| 925a9b1388 | |||
| fc942fdeca | |||
| 75a6ecbf52 | |||
| 520045441b | |||
| 00c3e966d3 | |||
| 8b6ebe86b8 | |||
| d5bd3453e1 | |||
| ddacbbe73b | |||
| f7d52f0eff | |||
| 39c50640ea | |||
| 16128c7e60 | |||
| 8b6a80cffb | |||
| 86f8a9d8fb | |||
| 790dfd601e | |||
| 3426428142 | |||
| 6c5c8e6eb7 | |||
| 3aefcaea73 | |||
| 04c025774d | |||
| 80aac7f581 | |||
| 266f7ca73d | |||
| 6bbefad24e | |||
| d6eb8e4c60 | |||
| c87edb155a | |||
| ef0468ad5d | |||
| f03153eb0c | |||
| 3d8b6e550a | |||
| 4c3dbca5ca | |||
| a258feea37 | |||
| 3a3332d0b9 | |||
| 4259283f32 | |||
| 243d977cd6 | |||
| 94bbbecedf | |||
| f49eab42a9 | |||
| ce6b2bc47d | |||
| 3245d7e430 | |||
| 6ee17c32ae | |||
| bf7ffe6d4c | |||
| ec7bc6b347 | |||
| b425db0979 | |||
| 30c6d1c9de | |||
| cee1d90fc6 | |||
| 522342667c | |||
| d1c1277bb9 | |||
| 9a66f56c79 | |||
| 087ca28ca2 | |||
| 3d5281ff3a | |||
| f62cf340c5 | |||
| 7e12bd3588 | |||
| 4dbdb95ebe | |||
| 2c5ddbcd8f | |||
| be4fd74f90 | |||
| 57491e3a8b | |||
| f7a442d297 | |||
| cfebdc6f6b | |||
| 65319e8fd6 | |||
| 55db44a3b4 | |||
| 13b6045300 | |||
| b7ff879c31 | |||
| 57ade87fe1 | |||
| 907e9ea5a7 | |||
| 215488dc45 | |||
| a195b3eac2 | |||
| 77c6f0e967 | |||
| f0e18afec1 | |||
| b6d11d88b7 | |||
| c803270af8 | |||
| 5d51263a58 | |||
| 7e30720b2c | |||
| 771c5e8b68 | |||
| 8f53afab6b | |||
| 0ad0403d41 | |||
| 2515c1dd73 | |||
| 7dfcd102dd | |||
| a91245d575 | |||
| 5f207f5e14 | |||
| 718692de3b | |||
| 9856a51255 | |||
| 58eaaf5514 | |||
| c0ae0138f8 | |||
| b1b9dc5b0a | |||
| f85c5a6498 | |||
| 32eafefc45 | |||
| 336999a34e | |||
| 1bf5f3b984 | |||
| c76d070237 | |||
| 8c7da1351f | |||
| 34588c6092 | |||
| 9f00bf8060 | |||
| f4a17b182f | |||
| 5c3b345fa6 | |||
| 46321fffd9 | |||
| 1f4cf33dd0 | |||
| 7274aa6940 | |||
| 125e804cd5 | |||
| 89ba17de84 | |||
| 115fba837c | |||
| 4df51546b2 | |||
| f68aaf7ff9 | |||
| e3d1746ba3 | |||
| a0d5646034 | |||
| 2f8af5f136 | |||
| 8b7abbd6f4 | |||
| f228f646eb | |||
| 45891d80c7 | |||
| ac900aa37f | |||
| 422cbed796 | |||
| 38cbbe46aa | |||
| c1b57a387b | |||
| aaa9ae8bb7 | |||
| 6340a64cff | |||
| 96bcfa4e20 | |||
| af0f56b26b | |||
| aed5befa48 | |||
| 8e37da672d | |||
| c0f68c45e2 | |||
| 47fdd73791 | |||
| 7c0b88cf2e | |||
| bf21633b6c | |||
| ad9b1fd6f7 | |||
| d245895085 | |||
| c7439d12f7 | |||
| 8d6923ce2c | |||
| b21fb24a82 | |||
| e7be132194 | |||
| 0e1717f4bb | |||
| 276dbe29c7 | |||
| 21fd5924b8 | |||
| 443def6cfd | |||
| 75464574d7 | |||
| 86f05c68c5 | |||
| 8dd407eaa8 | |||
| ea7ad10e8a | |||
| 62ec695dc8 | |||
| ca37ac73a9 | |||
| 96edd50c8f | |||
| 3993c1e35a | |||
| 5298558925 | |||
| c6ba147917 | |||
| 7efecea3d6 | |||
| a73fed3ebd | |||
| 50ef7bcd23 | |||
| 82e422cb89 | |||
| dab46c779d | |||
| 7c65adc9b2 | |||
| 9b96ef9bae | |||
| e97d1941dc | |||
| 0b0ac46e34 | |||
| 622bbcb8ea | |||
| 58a5245d21 | |||
| 612f9a6dc7 | |||
| 90d4dff263 | |||
| 0f38385c7d | |||
| 2b50616251 | |||
| 5b7f37f0d4 | |||
| 6ca8e26741 | |||
| a3ada05598 | |||
| 42eb11aaff | |||
| b581859afd | |||
| 2e22fae52a | |||
| 603ac8b91d | |||
| 5faa4841ca | |||
| 7416b826e0 | |||
| 82afc34755 | |||
| da39631a5a | |||
| fc8685a7c1 | |||
| 5e0204a980 | |||
| 6bb0f33f39 | |||
| ed4fd565b2 | |||
| 79cff28abd | |||
| 27329239f7 | |||
| 9de86fc0e4 | |||
| 7fa7826372 | |||
| 96ecfd098b | |||
| f7fe976c7e | |||
| 756629b91d | |||
| e640d124d4 | |||
| 7f41466297 | |||
| 57dfc062d2 | |||
| 799815d85a | |||
| 2946246834 | |||
| 6d276d1e79 | |||
| 6a3a369b3e | |||
| 5d8afa2135 | |||
| ab3e6aa8ce | |||
| 822092736e | |||
| 7497acd2e3 | |||
| ae137885b8 | |||
| b964cc7009 | |||
| c2ea126c5f | |||
| b668dba479 | |||
| 2cae5a0310 | |||
| b6a0f3ff67 | |||
| fa00b52fb5 | |||
| 2999d90907 | |||
| b6696bcad2 | |||
| 728c87c525 | |||
| ace394ee2d | |||
| 076ee98f64 | |||
| 2e472654ca | |||
| d46bd14678 | |||
| b3e5b3d106 | |||
| b830ef5dca | |||
| 45326c4ad2 | |||
| 603b61e8c8 | |||
| efb066c8e3 | |||
| c30db427b1 | |||
| 23056fc85d | |||
| 5f1bfc0280 | |||
| b715901f92 | |||
| 38fea06cf9 | |||
| 4481b5f556 | |||
| 0e0d051f7c | |||
| a1b649a279 | |||
| e6bc0a0fb7 | |||
| 93e4016c09 | |||
| 20c741a248 | |||
| 54f530c7c3 | |||
| 9fdc5da22d | |||
| 99ce48b146 | |||
| 6a33ad9ef7 | |||
| ca94055adf | |||
| 36a67e4c91 | |||
| 69431e1bbb | |||
| a3fc4ee2b0 | |||
| e505fd6d54 | |||
| 93a3785e4c | |||
| a02de84812 | |||
| c0521f0ec7 | |||
| 83d8c16853 | |||
| 47e9506397 | |||
| b8a3d0e254 | |||
| 001d7ec44e | |||
| 5cb0ec447a | |||
| 67e7d77302 | |||
| 8cbd8b2b48 | |||
| 7c404dbf96 | |||
| c4a67b6f2f | |||
| 3b70347625 | |||
| bb0a7935e9 | |||
| 8f4b799d3c | |||
| 931e0c66c9 | |||
| 0212084862 | |||
| 9abbabbce3 | |||
| ac610487e8 | |||
| a9a0f89892 | |||
| 305f221077 | |||
| 53514f2602 | |||
| 00327778cb | |||
| 37fadec787 | |||
| ada11d0b59 | |||
| 4c90fdb7b2 | |||
| 98c133df3c | |||
| f86c27b090 | |||
| b5b8ed72a5 | |||
| 5beff86548 | |||
| dd395edae1 | |||
| d1c1d7b75b | |||
| 4a380e9279 | |||
| 878c105def | |||
| 74d628676b | |||
| 6fdd98ec3a | |||
| 2ed1be3533 | |||
| 0ac04e1584 | |||
| 2a38d33d8a | |||
| fb14caf5b3 | |||
| cf51772f54 | |||
| cc8516df83 | |||
| c6a624bc6b | |||
| 8be8b825ee | |||
| 56eb4a2897 | |||
| 7a461eaa61 | |||
| fd64c05809 | |||
| 6bce93d893 | |||
| c9db068227 | |||
| 8a6d36ac4d | |||
| 64622c5945 | |||
| 837813edb0 | |||
| 0d9d62f1a9 | |||
| f7e9abf984 | |||
| dd0579b60d | |||
| b5bb953e47 | |||
| ef4a8ea1b6 | |||
| 49cde96ee7 | |||
| 627be20e48 | |||
| e45bb84b02 | |||
| 4e8876c725 |
@@ -23,3 +23,8 @@ build/Release
|
||||
# Deployed apps should consider commenting this line out:
|
||||
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
|
||||
theme/javascript/vendors
|
||||
|
||||
# vim swapfile
|
||||
*.swp
|
||||
|
||||
@@ -2,4 +2,3 @@ language: node_js
|
||||
node_js:
|
||||
- "0.11"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
|
||||
@@ -15,3 +15,4 @@ Contributors
|
||||
------------
|
||||
|
||||
- Nijiko Yonskai
|
||||
- Herman Starikov
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Release notes
|
||||
|
||||
## 0.6.0
|
||||
- Generate header id the same as github
|
||||
- Custom links can be added at top of sidebar
|
||||
- Summary can now be transformed by plugins
|
||||
- Support importing code snippets
|
||||
+21
-12
@@ -4,10 +4,18 @@ module.exports = function (grunt) {
|
||||
// Load NPM tasks
|
||||
grunt.loadNpmTasks('grunt-contrib-less');
|
||||
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
||||
grunt.loadNpmTasks("grunt-bower-install-simple");
|
||||
|
||||
// Init GRUNT configuraton
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
'bower-install-simple': {
|
||||
options: {
|
||||
color: true,
|
||||
production: false,
|
||||
directory: "theme/javascript/vendors"
|
||||
}
|
||||
},
|
||||
less: {
|
||||
development: {
|
||||
options: {
|
||||
@@ -16,27 +24,28 @@ module.exports = function (grunt) {
|
||||
optimization: 2
|
||||
},
|
||||
files: {
|
||||
"theme/assets/style.css": "theme/stylesheets/main.less",
|
||||
"theme/assets/print.css": "theme/stylesheets/print.less"
|
||||
"theme/assets/style.css": "theme/stylesheets/website.less",
|
||||
"theme/assets/print.css": "theme/stylesheets/ebook.less"
|
||||
}
|
||||
}
|
||||
},
|
||||
requirejs: {
|
||||
compile: {
|
||||
options: {
|
||||
name: "app",
|
||||
name: "gitbook",
|
||||
baseUrl: "theme/javascript/",
|
||||
out: "theme/assets/app.js",
|
||||
preserveLicenseComments: false,
|
||||
optimize: "uglify", //"uglify",
|
||||
include: ["requireLib"],
|
||||
paths: {
|
||||
"jQuery": 'vendors/jquery',
|
||||
"lodash": 'vendors/lodash',
|
||||
"requireLib": 'vendors/require',
|
||||
"Mousetrap": 'vendors/mousetrap',
|
||||
"mixpanel": 'vendors/mixpanel',
|
||||
"lunr": path.join(__dirname, "node_modules/lunr/lunr")
|
||||
"jQuery": 'vendors/jquery/dist/jquery',
|
||||
"lodash": 'vendors/lodash/dist/lodash',
|
||||
"requireLib": 'vendors/requirejs/require',
|
||||
"Mousetrap": 'vendors/mousetrap/mousetrap',
|
||||
"lunr": 'vendors/lunr.js/lunr',
|
||||
"URI": 'vendors/URIjs/src/URI',
|
||||
"ace": 'vendors/ace-builds/src-noconflict/'
|
||||
},
|
||||
shim: {
|
||||
'jQuery': {
|
||||
@@ -48,9 +57,6 @@ module.exports = function (grunt) {
|
||||
'Mousetrap': {
|
||||
exports: 'Mousetrap'
|
||||
},
|
||||
'mixpanel': {
|
||||
exports: 'mixpanel'
|
||||
},
|
||||
'lunr': {
|
||||
exports: 'lunr'
|
||||
}
|
||||
@@ -60,8 +66,11 @@ module.exports = function (grunt) {
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask("bower-install", [ "bower-install-simple" ]);
|
||||
|
||||
// Build
|
||||
grunt.registerTask('build', [
|
||||
'bower-install',
|
||||
'less',
|
||||
'requirejs'
|
||||
]);
|
||||
|
||||
@@ -186,7 +186,7 @@ Apache License
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
Copyright 2014 FriendCode Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -198,4 +198,4 @@ Apache License
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
limitations under the License.
|
||||
|
||||
@@ -3,7 +3,7 @@ GitBook
|
||||
|
||||
[](https://travis-ci.org/GitbookIO/gitbook)
|
||||
|
||||
GitBook is a command line tool (and Node.js library) for building beautiful programming books and exercises using GitHub/Git and Markdown. You can see an example: [Learn Javascript](http://gitbookio.github.io/javascript/).
|
||||
GitBook is a command line tool (and Node.js library) for building beautiful books and exercises using GitHub/Git and Markdown. Here is an example: [Learn Javascript](https://www.gitbook.io/book/GitBookIO/javascript). You can publish book easily online using [gitbook.io](https://www.gitbook.io) and an [editor](https://github.com/GitbookIO/editor) is available for Windows, Mac and Linux. You can follow [@GitBookIO](https://twitter.com/GitBookIO) on Twitter. Complete documentation is available at [help.gitbook.io](http://help.gitbook.io/).
|
||||
|
||||

|
||||
|
||||
@@ -30,32 +30,127 @@ $ gitbook build ./repository --output=./outputFolder
|
||||
Options for commands `build` and `serve` are:
|
||||
|
||||
```
|
||||
-t, --title <name> Name of the book to generate, defaults to repo name
|
||||
-i, --intro <intro> Description of the book to generate
|
||||
-g, --github <repo_path> ID of github repo like : username/repo
|
||||
-o, --output <directory> Path to output directory, defaults to ./_book
|
||||
-f, --format <name> Change generation format, defaults to site, availables are: site, page, pdf, json
|
||||
--githubHost <url> The url of the github host (defaults to https://github.com/)
|
||||
--theme <path> Path to theme directory
|
||||
-f, --format <name> Change generation format, defaults to site, availables are: site, page, ebook, json
|
||||
--config <config file> Configuration file to use, defaults to book.js or book.json
|
||||
```
|
||||
|
||||
GitBook loads the default configuration from a `book.json` file in the repository if it exists.
|
||||
|
||||
Here are the options that can be stored in this file:
|
||||
|
||||
```js
|
||||
{
|
||||
// Folders to use for output
|
||||
// Caution: it overrides the value from the command line
|
||||
// It's not advised this option in the book.json
|
||||
"output": null,
|
||||
|
||||
// Generator to use for building
|
||||
// Caution: it overrides the value from the command line
|
||||
// It's not advised this option in the book.json
|
||||
"generator": "site",
|
||||
|
||||
// Book title and description (defaults are extracted from the README)
|
||||
"title": null,
|
||||
"description": null,
|
||||
|
||||
// For ebook format, the extension to use for generation (default is detected from output extension)
|
||||
// "epub", "pdf", "mobi"
|
||||
// Caution: it overrides the value from the command line
|
||||
// It's not advised this option in the book.json
|
||||
"extension": null,
|
||||
|
||||
// GitHub information (defaults are extracted using git)
|
||||
"github": null,
|
||||
"githubHost": "https://github.com/",
|
||||
|
||||
// Plugins list, can contain "-name" for removing default plugins
|
||||
"plugins": [],
|
||||
|
||||
// Global configuration for plugins
|
||||
"pluginsConfig": {
|
||||
"fontSettings": {
|
||||
"theme": "sepia", "night" or "white",
|
||||
"family": "serif" or "sans",
|
||||
"size": 1 to 4
|
||||
}
|
||||
},
|
||||
|
||||
// Set another theme with your own layout
|
||||
// It's recommended to use plugins or add more options for default theme, though
|
||||
// See https://github.com/GitbookIO/gitbook/issues/209
|
||||
"theme": "./localtheme",
|
||||
|
||||
// Links in template (null: default, false: remove, string: new value)
|
||||
"links": {
|
||||
// Link to home in the top-left corner
|
||||
"home": null,
|
||||
|
||||
// Links in top of sidebar
|
||||
"about": null,
|
||||
"issues": null,
|
||||
"contribute": null,
|
||||
|
||||
// Custom links at top of sidebar
|
||||
"custom": {
|
||||
"Custom link name": "https://customlink.com"
|
||||
},
|
||||
|
||||
// Sharing links
|
||||
"sharing": {
|
||||
"google": null,
|
||||
"facebook": null,
|
||||
"twitter": null
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// Options for PDF generation
|
||||
"pdf": {
|
||||
// Add toc at the end of the file
|
||||
"toc": true,
|
||||
|
||||
// Add page numbers to the bottom of every page
|
||||
"pageNumbers": false,
|
||||
|
||||
// Font size for the fiel content
|
||||
"fontSize": 12,
|
||||
|
||||
// Paper size for the pdf
|
||||
// Choices are [u’a0’, u’a1’, u’a2’, u’a3’, u’a4’, u’a5’, u’a6’, u’b0’, u’b1’, u’b2’, u’b3’, u’b4’, u’b5’, u’b6’, u’legal’, u’letter’]
|
||||
"paperSize": "a4",
|
||||
|
||||
// Margin (in pts)
|
||||
// Note: 72 pts equals 1 inch
|
||||
"margin": {
|
||||
"right": 62,
|
||||
"left": 62,
|
||||
"top": 36,
|
||||
"bottom": 36
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can publish your books to our index by visiting [GitBook.io](http://www.gitbook.io)
|
||||
|
||||
## Output Formats
|
||||
|
||||
GitBook can generate your book in the following formats:
|
||||
|
||||
* **Static Website**: This is the default format, it generates a complete interactive static website that can be for example hosted on GitHub Pages.
|
||||
* **PDF**: A complete PDF book with exercise solutions at the end of the book. Generate to this format using: ```gitbook pdf ./myrepo```, you need to have [gitbook-pdf](https://github.com/GitbookIO/gitbook-pdf) installed.
|
||||
* **eBook**: A complete eBook with exercise solutions at the end of the book. Generate to this format using: ```gitbook ebook ./myrepo```, you need to have [ebook-convert](http://manual.calibre-ebook.com/cli/ebook-convert.html) installed.
|
||||
* **Single Page**: The book will be stored in a single printable HTML page, this format is used for conversion to PDF or eBook. Generate to this format using: ```gitbook build ./myrepo -f page```.
|
||||
* **JSON**: This format is used for debugging or extracting metadata from a book. Generate to this format using: ```gitbook build ./myrepo -f json```.
|
||||
* **Static Website**: This is the default format. It generates a complete interactive static website that can be, for example, hosted on GitHub Pages.
|
||||
* **eBook**: A complete eBook with exercise solutions at the end of the book. Generate this format using: ```gitbook ebook ./myrepo```. You need to have [ebook-convert](http://manual.calibre-ebook.com/cli/ebook-convert.html) installed. The output format could be **PDF**, **ePub** or **MOBI**.
|
||||
* **Single Page**: The book will be stored in a single printable HTML page. This format is used for conversion to PDF or eBook. Generate this format using: ```gitbook build ./myrepo -f page```.
|
||||
* **JSON**: This format is used for debugging or extracting metadata from a book. Generate this format using: ```gitbook build ./myrepo -f json```.
|
||||
|
||||
## Book Format
|
||||
|
||||
A book is a GitHub repository containing at least 2 files: `README.md` and `SUMMARY.md`.
|
||||
A book is a Git repository containing at least 2 files: `README.md` and `SUMMARY.md`.
|
||||
|
||||
#### README.md
|
||||
|
||||
As usual, it should contains an introduction for your book. It will be automatically added to the final summary.
|
||||
Typically, this should be the introduction for your book. It will be automatically added to the final summary.
|
||||
|
||||
#### SUMMARY.md
|
||||
|
||||
@@ -75,11 +170,11 @@ This is the summary of my book.
|
||||
* [example 1](section2/example1.md)
|
||||
```
|
||||
|
||||
Files that are not included in the `SUMMARY.md` will not be processed by `gitbook`.
|
||||
Files that are not included in `SUMMARY.md` will not be processed by `gitbook`.
|
||||
|
||||
#### Exercises
|
||||
|
||||
A book can contain interactive exercises (currently only in Javascript but Python and Ruby are coming soon ;) ). An exercise is a code challenge provided to the reader, which is given a code editor to write a solution which is checked against the book author's validation code.
|
||||
A book can contain interactive exercises (currently only in Javascript but Python and Ruby are coming soon ;) ). An exercise is a code challenge provided to the reader, who is given a code editor to write a solution which is checked against the book author's validation code.
|
||||
|
||||
An exercise is defined by 4 simple parts:
|
||||
|
||||
@@ -88,7 +183,7 @@ An exercise is defined by 4 simple parts:
|
||||
* **Solution** code, being a correct solution to the exercise
|
||||
* **Validation** code that tests the correctness of the user's input
|
||||
|
||||
Exercises need to start and finish with a separation bar (```---``` or ```***```). It should contain 3 code elements (**base**, **solution** and **validation**). It can contain a 4th element that provides **context** code (functions, imports of libraries etc ... that shouldn't be displayed to the user).
|
||||
Exercises need to start and finish with a separation bar (```---``` or ```***```). It should contain 3 code elements (**base**, **solution** and **validation**). It can contain a 4th element that provides **context** code (functions, imports of libraries, etc which shouldn't be displayed to the user).
|
||||
|
||||
---
|
||||
|
||||
@@ -130,4 +225,46 @@ You can see a complete example with the [Learn Git](https://github.com/GitbookIO
|
||||
|
||||
#### Ignoring files & folders
|
||||
|
||||
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`)
|
||||
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`)
|
||||
|
||||
#### Cover
|
||||
|
||||
A cover image can be set by creating a file: **/cover.jpg**.
|
||||
The best resolution is **1800x2360**. The generation of the cover can be done automatically using the plugin [autocover](https://github.com/GitbookIO/plugin-autocover).
|
||||
|
||||
A small version of the cover can also be set by creating a file: **/cover_small.jpg**.
|
||||
|
||||
#### Publish your book
|
||||
|
||||
The platform [GitBook.io](https://www.gitbook.io/) is like an "Heroku for books": you can create a book on it (public, paid, or private) and update it using **git push**.
|
||||
|
||||
#### Plugins
|
||||
|
||||
Plugins can used to extend your book's functionality. Read [GitbookIO/plugin](https://github.com/GitbookIO/plugin) for more information about how to build a plugin for GitBook.
|
||||
|
||||
##### Default plugins:
|
||||
|
||||
* [mathjax](https://github.com/GitbookIO/plugin-mathjax): displays mathematical notation in the book.
|
||||
* [mixpanel](https://github.com/GitbookIO/plugin-mixpanel): Mixpanel tracking for your book
|
||||
|
||||
##### Other plugins:
|
||||
|
||||
* [Google Analytics](https://github.com/GitbookIO/plugin-ga): Google Analytics tracking for your book
|
||||
* [Disqus](https://github.com/GitbookIO/plugin-disqus): Disqus comments integration in your book
|
||||
* [Autocover](https://github.com/GitbookIO/plugin-autocover): Generate a cover for your book
|
||||
* [Transform annoted quotes to notes](https://github.com/erixtekila/gitbook-plugin-richquotes): Allow extra markdown markup to render blockquotes as nice notes
|
||||
* [Send code to console](https://github.com/erixtekila/gitbook-plugin-toconsole): Evaluate javascript block in the browser inspector's console
|
||||
* [Revealable sections](https://github.com/mrpotes/gitbook-plugin-reveal): Reveal sections of the page using buttons made from the first title in each section
|
||||
* [Markdown within HTML](https://github.com/mrpotes/gitbook-plugin-nestedmd): Process markdown within HTML blocks - allows custom layout options for individual pages
|
||||
* [Bootstrap JavaScript plugins](https://github.com/mrpotes/gitbook-plugin-bootstrapjs): Use the [Bootstrap JavaScript plugins](http://getbootstrap.com/javascript) in your online GitBook
|
||||
* [Piwik Open Analytics](https://github.com/emmanuel-keller/gitbook-plugin-piwik): Piwik Open Analytics tracking for your book
|
||||
* [Heading Anchors](https://github.com/rlmv/gitbook-plugin-anchors): Add linkable Github-style anchors to headings
|
||||
|
||||
#### Debugging
|
||||
|
||||
You can use the environment variable `DEBUG=true` to get better error messages (with stack trace). For example:
|
||||
|
||||
```
|
||||
$ export DEBUG=true
|
||||
$ gitbook build ./
|
||||
```
|
||||
|
||||
+43
-30
@@ -1,50 +1,63 @@
|
||||
var path = require('path');
|
||||
var Q = require('q');
|
||||
var _ = require('lodash');
|
||||
var fs = require('fs');
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
var generate = require("../lib/generate");
|
||||
var parse = require("../lib/parse");
|
||||
var fs = require('../lib/generate/fs');
|
||||
var generators = require("../lib/generate").generators;
|
||||
|
||||
var buildCommand = function(command) {
|
||||
return command
|
||||
.option('-v, --verbose', 'Activate verbose mode, useful for debugging errors')
|
||||
.option('-o, --output <directory>', 'Path to output directory, defaults to ./_book')
|
||||
.option('-f, --format <name>', 'Change generation format, defaults to site, availables are: '+_.keys(generators).join(", "))
|
||||
.option('--config <config file>', 'Configuration file to use, defaults to book.js or book.json');
|
||||
};
|
||||
|
||||
|
||||
var buildEbookCommand = function(command) {
|
||||
return buildCommand(command)
|
||||
.option('-c, --cover <path>', 'Cover image, default is cover.jpg if exists');
|
||||
};
|
||||
|
||||
var makeBuildFunc = function(converter) {
|
||||
return function(dir, options) {
|
||||
dir = dir || process.cwd();
|
||||
outputDir = options.output
|
||||
outputDir = options.output;
|
||||
|
||||
// Set debugging
|
||||
if(options.verbose) {
|
||||
process.env.DEBUG = "true";
|
||||
}
|
||||
|
||||
console.log('Starting build ...');
|
||||
// Get repo's URL
|
||||
return utils.gitURL(dir)
|
||||
.then(function(url) {
|
||||
// Get ID of repo
|
||||
return utils.githubID(url);
|
||||
}, function(err) {
|
||||
return null;
|
||||
})
|
||||
.then(function(repoID) {
|
||||
return converter(
|
||||
_.extend(options || {}, {
|
||||
input: dir,
|
||||
output: outputDir,
|
||||
title: options.title,
|
||||
description: options.intro,
|
||||
github: options.github || repoID,
|
||||
githubHost: options.githubHost,
|
||||
generator: options.format,
|
||||
theme: options.theme
|
||||
})
|
||||
);
|
||||
})
|
||||
return converter(
|
||||
_.extend({}, options || {}, {
|
||||
input: dir,
|
||||
output: outputDir,
|
||||
generator: options.format,
|
||||
configFile: options.config
|
||||
})
|
||||
)
|
||||
.then(function(output) {
|
||||
console.log("Successfuly built !");
|
||||
console.log("Successfully built!");
|
||||
return output;
|
||||
}, utils.logError);
|
||||
};
|
||||
}
|
||||
})
|
||||
.fail(function(err) {
|
||||
// Log error
|
||||
utils.logError(err);
|
||||
|
||||
// Exit process with failure code
|
||||
process.exit(-1);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
folder: makeBuildFunc(generate.folder),
|
||||
file: makeBuildFunc(generate.file)
|
||||
file: makeBuildFunc(generate.file),
|
||||
command: buildCommand,
|
||||
commandEbook: buildEbookCommand
|
||||
};
|
||||
|
||||
+85
-33
@@ -4,6 +4,7 @@ var Q = require('q');
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var prog = require('commander');
|
||||
var tinylr = require('tiny-lr-fork');
|
||||
|
||||
var pkg = require('../package.json');
|
||||
var generators = require("../lib/generate").generators;
|
||||
@@ -12,62 +13,97 @@ var fs = require('../lib/generate/fs');
|
||||
|
||||
var utils = require('./utils');
|
||||
var build = require('./build');
|
||||
var Server = require('./server');
|
||||
var platform = require("./platform");
|
||||
|
||||
// General options
|
||||
prog
|
||||
.version(pkg.version);
|
||||
|
||||
var buildCommand = function(command) {
|
||||
return command
|
||||
.option('-o, --output <directory>', 'Path to output directory, defaults to ./_book')
|
||||
.option('-f, --format <name>', 'Change generation format, defaults to site, availables are: '+_.keys(generators).join(", "))
|
||||
.option('-t, --title <name>', 'Name of the book to generate, default is extracted from readme')
|
||||
.option('-i, --intro <intro>', 'Description of the book to generate, default is extracted from readme')
|
||||
.option('-g, --github <repo_path>', 'ID of github repo like : username/repo')
|
||||
.option('--githubHost <url>', 'The url of the github host (defaults to https://github.com/')
|
||||
.option('--theme <path>', 'Path to theme directory');
|
||||
};
|
||||
|
||||
buildCommand(prog.command('build [source_dir]'))
|
||||
build.command(prog.command('build [source_dir]'))
|
||||
.description('Build a gitbook from a directory')
|
||||
.action(build.folder);
|
||||
|
||||
buildCommand(prog.command('serve [source_dir]'))
|
||||
build.command(prog.command('serve [source_dir]'))
|
||||
.description('Build then serve a gitbook from a directory')
|
||||
.option('-p, --port <port>', 'Port for server to listen on', 4000)
|
||||
.option('--no-watch', 'Disable restart with file watching')
|
||||
.action(function(dir, options) {
|
||||
build.folder(dir, options || {})
|
||||
.then(function(_options) {
|
||||
console.log();
|
||||
console.log('Starting server ...');
|
||||
return utils.serveDir(_options.output, options.port)
|
||||
.fail(utils.logError);
|
||||
})
|
||||
.then(function() {
|
||||
console.log('Serving book on http://localhost:'+options.port);
|
||||
console.log();
|
||||
console.log('Press CTRL+C to quit ...');
|
||||
var server = new Server();
|
||||
|
||||
// init livereload server
|
||||
var lrOptions = {port: 35729};
|
||||
var lrServer = tinylr(lrOptions);
|
||||
var lrPath = undefined;
|
||||
lrServer.listen(lrOptions.port, function(err) {
|
||||
if (err) { return console.log(err); }
|
||||
console.log('Live reload server started on port: ' + lrOptions.port);
|
||||
});
|
||||
|
||||
var generate = function() {
|
||||
if (server.isRunning()) console.log("Stopping server");
|
||||
|
||||
server.stop()
|
||||
.then(function() {
|
||||
return build.folder(dir, _.extend(options || {}, {
|
||||
cache: false,
|
||||
defaultsPlugins: ["livereload"]
|
||||
}));
|
||||
})
|
||||
.then(function(_options) {
|
||||
console.log();
|
||||
console.log('Starting server ...');
|
||||
return server.start(_options.output, options.port)
|
||||
.then(function() {
|
||||
console.log('Serving book on http://localhost:'+options.port);
|
||||
|
||||
if (lrPath) {
|
||||
// trigger livereload
|
||||
lrServer.changed({body:{files:[lrPath]}})
|
||||
}
|
||||
|
||||
if (!options.watch) return;
|
||||
return utils.watch(_options.input)
|
||||
.then(function(filepath) {
|
||||
// set livereload path
|
||||
lrPath = filepath;
|
||||
console.log("Restart after change in files");
|
||||
console.log('');
|
||||
return generate();
|
||||
})
|
||||
})
|
||||
})
|
||||
.fail(utils.logError);
|
||||
};
|
||||
|
||||
console.log('Press CTRL+C to quit ...');
|
||||
console.log('')
|
||||
generate();
|
||||
});
|
||||
|
||||
buildCommand(prog.command('pdf [source_dir]'))
|
||||
build.commandEbook(prog.command('pdf [source_dir]'))
|
||||
.description('Build a gitbook as a PDF')
|
||||
.option('-pf, --paperformat <format>', 'PDF paper format (default is A4): "5in*7.5in", "10cm*20cm", "A4", "Letter"')
|
||||
.action(function(dir, options) {
|
||||
build.file(dir, _.extend(options, {
|
||||
extension: "pdf",
|
||||
format: "pdf"
|
||||
format: "ebook"
|
||||
}));
|
||||
});
|
||||
|
||||
buildCommand(prog.command('ebook [source_dir]'))
|
||||
.description('Build a gitbook as a eBook')
|
||||
.option('-c, --cover <path>', 'Cover image, default is cover.png if exists')
|
||||
build.commandEbook(prog.command('epub [source_dir]'))
|
||||
.description('Build a gitbook as a ePub book')
|
||||
.action(function(dir, options) {
|
||||
var ext = options.output ? path.extname(options.output) : "epub";
|
||||
|
||||
build.file(dir, _.extend(options, {
|
||||
extension: ext,
|
||||
extension: "epub",
|
||||
format: "ebook"
|
||||
}));
|
||||
});
|
||||
|
||||
build.commandEbook(prog.command('mobi [source_dir]'))
|
||||
.description('Build a gitbook as a Mobi book')
|
||||
.action(function(dir, options) {
|
||||
build.file(dir, _.extend(options, {
|
||||
extension: "mobi",
|
||||
format: "ebook"
|
||||
}));
|
||||
});
|
||||
@@ -80,6 +116,22 @@ prog
|
||||
return initDir(dir);
|
||||
});
|
||||
|
||||
prog
|
||||
.command('publish [source_dir]')
|
||||
.description('Publish content to the associated gitbook.io book')
|
||||
.action(function(dir) {
|
||||
dir = dir || process.cwd();
|
||||
return platform.publish(dir);
|
||||
});
|
||||
|
||||
prog
|
||||
.command('git:remote [source_dir] [book_id]')
|
||||
.description('Adds a git remote to a book repository')
|
||||
.action(function(dir, bookId) {
|
||||
dir = dir || process.cwd();
|
||||
return platform.remote(dir, bookId);
|
||||
});
|
||||
|
||||
// Parse and fallback to help if no args
|
||||
if(_.isEmpty(prog.parse(process.argv).args) && process.argv.length === 2) {
|
||||
prog.help();
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
var Q = require("q");
|
||||
var utils = require("./utils");
|
||||
|
||||
var publish = function(folder) {
|
||||
if (!folder) {
|
||||
console.log("Need a repository folder");
|
||||
return process.exit(-1);
|
||||
}
|
||||
|
||||
utils.gitCmd("push", ["gitbook", "master"])
|
||||
.then(function(out) {
|
||||
console.log(out.stdout);
|
||||
}, function(err) {
|
||||
if (err.code == 128) {
|
||||
console.log("No book on gitbook.io is configured with this git repository.");
|
||||
console.log("Run 'gitbook git:remote username/book' to intialize this repository.");
|
||||
} else {
|
||||
console.log(err.message);
|
||||
}
|
||||
process.exit(-1);
|
||||
});
|
||||
};
|
||||
|
||||
var remote = function(folder, bookId) {
|
||||
if (!folder || !bookId) {
|
||||
console.log("Need a repository folder and a book id");
|
||||
return process.exit(-1);
|
||||
}
|
||||
|
||||
var url = "https://push.gitbook.io/"+bookId+".git";
|
||||
var addRemote = function() {
|
||||
return utils.gitCmd("remote", ["add", "gitbook", url]);
|
||||
}
|
||||
|
||||
addRemote()
|
||||
.fail(function(err) {
|
||||
if (err.code == 128) {
|
||||
return utils.gitCmd("remote", ["rm", "gitbook"]).then(addRemote);
|
||||
}
|
||||
return Q.reject(err);
|
||||
})
|
||||
.then(function(out) {
|
||||
console.log("Book remote '"+url+"' added to the folder");
|
||||
}, function(err) {
|
||||
console.log(err.message);
|
||||
process.exit(-1);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
publish: publish,
|
||||
remote: remote
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
var Q = require('q');
|
||||
var _ = require('lodash');
|
||||
|
||||
var events = require('events');
|
||||
var http = require('http');
|
||||
var send = require('send');
|
||||
var util = require('util');
|
||||
var url = require('url');
|
||||
|
||||
var Server = function() {
|
||||
this.running = null;
|
||||
this.dir = null;
|
||||
this.port = 0;
|
||||
this.sockets = [];
|
||||
};
|
||||
util.inherits(Server, events.EventEmitter);
|
||||
|
||||
// Return true if the server is running
|
||||
Server.prototype.isRunning = function() {
|
||||
return this.running != null;
|
||||
};
|
||||
|
||||
// Stop the server
|
||||
Server.prototype.stop = function() {
|
||||
var that = this;
|
||||
if (!this.isRunning()) return Q();
|
||||
|
||||
var d = Q.defer();
|
||||
this.running.close(function(err) {
|
||||
that.running = null;
|
||||
that.emit("state", false);
|
||||
|
||||
if (err) d.reject(err);
|
||||
else d.resolve();
|
||||
});
|
||||
|
||||
for (var i = 0; i < this.sockets.length; i++) {
|
||||
this.sockets[i].destroy();
|
||||
}
|
||||
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
Server.prototype.start = function(dir, port) {
|
||||
var that = this, pre = Q();
|
||||
port = port || 8004;
|
||||
|
||||
if (that.isRunning()) pre = this.stop();
|
||||
return pre
|
||||
.then(function() {
|
||||
var d = Q.defer();
|
||||
|
||||
that.running = http.createServer(function(req, res){
|
||||
// Render error
|
||||
function error(err) {
|
||||
res.statusCode = err.status || 500;
|
||||
res.end(err.message);
|
||||
}
|
||||
|
||||
// Redirect to directory's index.html
|
||||
function redirect() {
|
||||
res.statusCode = 301;
|
||||
res.setHeader('Location', req.url + '/');
|
||||
res.end('Redirecting to ' + req.url + '/');
|
||||
}
|
||||
|
||||
// Send file
|
||||
send(req, url.parse(req.url).pathname)
|
||||
.root(dir)
|
||||
.on('error', error)
|
||||
.on('directory', redirect)
|
||||
.pipe(res);
|
||||
});
|
||||
|
||||
that.running.on('connection', function (socket) {
|
||||
that.sockets.push(socket);
|
||||
socket.setTimeout(4000);
|
||||
socket.on('close', function () {
|
||||
that.sockets.splice(that.sockets.indexOf(socket), 1);
|
||||
});
|
||||
});
|
||||
|
||||
that.running.listen(port, function(err) {
|
||||
if (err) return d.reject(err);
|
||||
|
||||
that.port = port;
|
||||
that.dir = dir;
|
||||
that.emit("state", true);
|
||||
d.resolve();
|
||||
});
|
||||
|
||||
return d.promise;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Server;
|
||||
+41
-76
@@ -1,101 +1,66 @@
|
||||
var Q = require('q');
|
||||
var _ = require('lodash');
|
||||
|
||||
var exec = require('child_process').exec;
|
||||
var http = require('http');
|
||||
var send = require('send');
|
||||
|
||||
var url = require('url');
|
||||
var cp = require('child_process');
|
||||
var path = require('path');
|
||||
var Gaze = require('gaze').Gaze;
|
||||
|
||||
|
||||
// Get the remote of a given repo
|
||||
function gitURL(path) {
|
||||
function watch(dir) {
|
||||
var d = Q.defer();
|
||||
dir = path.resolve(dir);
|
||||
|
||||
cp.exec("git config --get remote.origin.url", {
|
||||
cwd: path,
|
||||
env: process.env,
|
||||
}, function(err, stdout, stderr) {
|
||||
if(err) {
|
||||
return d.reject(err);
|
||||
}
|
||||
|
||||
return d.resolve(stdout);
|
||||
var gaze = new Gaze("**/*.md", {
|
||||
cwd: dir
|
||||
});
|
||||
|
||||
return d.promise
|
||||
.then(function(output) {
|
||||
return output.replace(/(\r\n|\n|\r)/gm, "");
|
||||
gaze.once("all", function(e, filepath) {
|
||||
gaze.close();
|
||||
|
||||
d.resolve(filepath);
|
||||
});
|
||||
}
|
||||
gaze.once("error", function(err) {
|
||||
gaze.close();
|
||||
|
||||
// Poorman's parsing
|
||||
// Parse a git URL to a github ID : username/reponame
|
||||
function githubID(_url) {
|
||||
// Remove .git if it's in _url
|
||||
var sliceEnd = _url.slice(-4) === '.git' ? -4 : _url.length;
|
||||
|
||||
// Detect HTTPS repos
|
||||
var parsed = url.parse(_url);
|
||||
if(parsed.protocol === 'https:' && parsed.host === 'github.com') {
|
||||
return parsed.path.slice(1, sliceEnd);
|
||||
}
|
||||
|
||||
// Detect SSH repos
|
||||
if(_url.indexOf('git@') === 0) {
|
||||
return _url.split(':', 2)[1].slice(0, sliceEnd);
|
||||
}
|
||||
|
||||
// None found
|
||||
return null;
|
||||
}
|
||||
|
||||
function titleCase(str)
|
||||
{
|
||||
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
||||
}
|
||||
|
||||
function serveDir(dir, port) {
|
||||
var d = Q.defer();
|
||||
|
||||
var server = http.createServer(function(req, res){
|
||||
// Render error
|
||||
function error(err) {
|
||||
res.statusCode = err.status || 500;
|
||||
res.end(err.message);
|
||||
}
|
||||
|
||||
// Redirect to directory's index.html
|
||||
function redirect() {
|
||||
res.statusCode = 301;
|
||||
res.setHeader('Location', req.url + '/');
|
||||
res.end('Redirecting to ' + req.url + '/');
|
||||
}
|
||||
|
||||
// Send file
|
||||
send(req, url.parse(req.url).pathname)
|
||||
.root(dir)
|
||||
.on('error', error)
|
||||
.on('directory', redirect)
|
||||
.pipe(res);
|
||||
}).listen(port);
|
||||
|
||||
d.resolve(server);
|
||||
d.reject(err);
|
||||
});
|
||||
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
function logError(err) {
|
||||
console.log(err.stack || err.message || err);
|
||||
var message = err.message || err;
|
||||
if (process.env.DEBUG != null) message = err.stack || message;
|
||||
console.log(message);
|
||||
return Q.reject(err);
|
||||
};
|
||||
|
||||
function runGitCommand(command, args) {
|
||||
var d = Q.defer(), child;
|
||||
args = ["git", command].concat(args).join(" ");
|
||||
|
||||
child = exec(args, function (error, stdout, stderr) {
|
||||
if (error !== null) {
|
||||
error.stdout = stdout;
|
||||
error.stderr = stderr;
|
||||
d.reject(error);
|
||||
} else {
|
||||
d.resolve({
|
||||
stdout: stdout,
|
||||
stderr: stderr
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
|
||||
// Exports
|
||||
module.exports = {
|
||||
gitURL: gitURL,
|
||||
githubID: githubID,
|
||||
titleCase: titleCase,
|
||||
serveDir: serveDir,
|
||||
logError: logError
|
||||
watch: watch,
|
||||
logError: logError,
|
||||
gitCmd: runGitCommand
|
||||
};
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "GitBook",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"jquery": "2.1.1",
|
||||
"lodash": "2.4.1",
|
||||
"requirejs": "2.1.11",
|
||||
"URIjs": "1.13.1",
|
||||
"mousetrap": "1.4.6",
|
||||
"lunr.js": "0.5.2",
|
||||
"ace-builds": "1.1.3"
|
||||
}
|
||||
}
|
||||
+42
-19
@@ -7,6 +7,7 @@ var exec = require('child_process').exec;
|
||||
var fs = require("fs");
|
||||
var parse = require("../../parse");
|
||||
var BaseGenerator = require("../page");
|
||||
var stringUtils = require("../../utils/string");
|
||||
|
||||
/*
|
||||
* This generator inherits from the single page generator
|
||||
@@ -14,15 +15,6 @@ var BaseGenerator = require("../page");
|
||||
*/
|
||||
var Generator = function() {
|
||||
BaseGenerator.apply(this, arguments);
|
||||
|
||||
// Options for eBook generation
|
||||
this.options = _.defaults(this.options, {
|
||||
extension: "epub"
|
||||
});
|
||||
|
||||
if (!this.options.cover && fs.existsSync(path.join(this.options.input, "cover.png"))) {
|
||||
this.options.cover = path.join(this.options.input, "cover.png")
|
||||
}
|
||||
};
|
||||
util.inherits(Generator, BaseGenerator);
|
||||
|
||||
@@ -32,23 +24,54 @@ Generator.prototype.finish = function() {
|
||||
return BaseGenerator.prototype.finish.apply(this)
|
||||
.then(function() {
|
||||
var d = Q.defer();
|
||||
var format = that.options.extension || path.extname(that.options.output).replace("\.", "") || "pdf";
|
||||
|
||||
if (!that.options.cover && fs.existsSync(path.join(that.options.output, "cover.jpg"))) {
|
||||
that.options.cover = path.join(that.options.output, "cover.jpg");
|
||||
}
|
||||
|
||||
var _options = {
|
||||
"--cover": that.options.cover
|
||||
"--cover": that.options.cover,
|
||||
"--title": that.options.title,
|
||||
"--comments": that.options.description,
|
||||
"--authors": that.options.author,
|
||||
"--level1-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-1 ')]",
|
||||
"--level2-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]",
|
||||
"--level3-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]"
|
||||
};
|
||||
|
||||
if (format == "pdf") {
|
||||
var pdfOptions = _.defaults(that.options.pdf || {}, {
|
||||
"fontSize": 12,
|
||||
"toc": true,
|
||||
"pageNumbers": false,
|
||||
"paperSize": "a4",
|
||||
"margin": {
|
||||
"right": 62,
|
||||
"left": 62,
|
||||
"top": 36,
|
||||
"bottom": 36
|
||||
}
|
||||
});
|
||||
|
||||
_.extend(_options, {
|
||||
"--margin-left": String(pdfOptions.margin.left),
|
||||
"--margin-right": String(pdfOptions.margin.right),
|
||||
"--margin-top": String(pdfOptions.margin.top),
|
||||
"--margin-bottom": String(pdfOptions.margin.bottom),
|
||||
"--pdf-add-toc": Boolean(pdfOptions.toc),
|
||||
"--pdf-default-font-size": String(pdfOptions.fontSize),
|
||||
"--pdf-mono-font-size": String(pdfOptions.fontSize),
|
||||
"--paper-size": String(pdfOptions.paperSize),
|
||||
"--pdf-page-numbers": Boolean(pdfOptions.pageNumbers)
|
||||
});
|
||||
}
|
||||
|
||||
var command = [
|
||||
"ebook-convert",
|
||||
path.join(that.options.output, "index.html"),
|
||||
path.join(that.options.output, "index."+that.options.extension),
|
||||
_.chain(_options)
|
||||
.map(function(value, key) {
|
||||
if (value == null) return null;
|
||||
return key+"="+value;
|
||||
})
|
||||
.compact()
|
||||
.value()
|
||||
.join(" ")
|
||||
path.join(that.options.output, "index."+format),
|
||||
stringUtils.optionsToShellArgs(_options)
|
||||
].join(" ");
|
||||
|
||||
exec(command, function (error, stdout, stderr) {
|
||||
|
||||
@@ -16,8 +16,20 @@ var getFiles = function(path) {
|
||||
|
||||
// Add extra rules to ignore common folders
|
||||
ig.addIgnoreRules([
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
'.gitignore',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'*.pdf',
|
||||
'*.epub',
|
||||
'*.mobi',
|
||||
], '__custom_stuff');
|
||||
|
||||
// Push each file to our list
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
var _ = require("lodash");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var fs = require("./fs");
|
||||
|
||||
var Plugin = require("./plugin");
|
||||
|
||||
var BaseGenerator = function(options) {
|
||||
this.options = options;
|
||||
|
||||
this.options.plugins = Plugin.normalizeNames(this.options.plugins);
|
||||
this.options.plugins = _.union(this.options.plugins, this.options.defaultsPlugins);
|
||||
this.plugins = [];
|
||||
};
|
||||
|
||||
BaseGenerator.prototype.callHook = function(name, data) {
|
||||
return this.plugins.hook(name, this, data);
|
||||
};
|
||||
|
||||
BaseGenerator.prototype.loadPlugins = function() {
|
||||
var that = this;
|
||||
|
||||
return Plugin.fromList(this.options.plugins, this.options.input)
|
||||
.then(function(_plugins) {
|
||||
that.plugins = _plugins;
|
||||
|
||||
return that.callHook("init");
|
||||
});
|
||||
};
|
||||
|
||||
BaseGenerator.prototype.convertFile = function(content, input) {
|
||||
@@ -23,6 +45,27 @@ BaseGenerator.prototype.transferFolder = function(input) {
|
||||
);
|
||||
};
|
||||
|
||||
BaseGenerator.prototype.copyCover = function() {
|
||||
var that = this;
|
||||
|
||||
return Q.all([
|
||||
fs.copy(path.join(this.options.input, "cover.jpg"), path.join(this.options.output, "cover.jpg")),
|
||||
fs.copy(path.join(this.options.input, "cover_small.jpg"), path.join(this.options.output, "cover_small.jpg"))
|
||||
])
|
||||
.fail(function() {
|
||||
// If orignally from multi-lang, try copy from originalInput
|
||||
if (!that.options.originalInput) return;
|
||||
|
||||
return Q.all([
|
||||
fs.copy(path.join(that.options.originalInput, "cover.jpg"), path.join(that.options.output, "cover.jpg")),
|
||||
fs.copy(path.join(that.options.originalInput, "cover_small.jpg"), path.join(that.options.output, "cover_small.jpg"))
|
||||
]);
|
||||
})
|
||||
.fail(function(err) {
|
||||
return Q();
|
||||
});
|
||||
};
|
||||
|
||||
BaseGenerator.prototype.langsIndex = function(langs) {
|
||||
return Q.reject(new Error("Langs index is not supported in this generator"));
|
||||
};
|
||||
|
||||
+280
-107
@@ -1,62 +1,252 @@
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
var path = require("path");
|
||||
var swig = require('swig');
|
||||
var tmp = require('tmp');
|
||||
|
||||
var swig = require('./template');
|
||||
var fs = require("./fs");
|
||||
var parse = require("../parse");
|
||||
var Plugin = require("./plugin");
|
||||
|
||||
var generators = {
|
||||
"site": require("./site"),
|
||||
"page": require("./page"),
|
||||
"pdf": require("./pdf"),
|
||||
"ebook": require("./ebook"),
|
||||
"json": require("./json")
|
||||
};
|
||||
|
||||
var defaultDescription = "Book generated using GitBook";
|
||||
|
||||
/*
|
||||
* Use a specific generator to convert a gitbook to a site/pdf/ebook/
|
||||
* output is always a folder
|
||||
*/
|
||||
var generate = function(options) {
|
||||
var generator = null;
|
||||
var files;
|
||||
|
||||
var containsFiles = function(dir, files) {
|
||||
return Q.all(_.map(files, function(file) {
|
||||
return fs.exists(path.join(dir, file));
|
||||
}))
|
||||
.then(_.all);
|
||||
};
|
||||
|
||||
// TEst if generator exists
|
||||
var checkGenerator = function(options) {
|
||||
if (!generators[options.generator]) {
|
||||
return Q.reject(new Error("Invalid generator (availables are: "+_.keys(generators).join(", ")+")"));
|
||||
}
|
||||
return Q();
|
||||
};
|
||||
|
||||
// Create the generator and load plugins
|
||||
var loadGenerator = function(options) {
|
||||
return checkGenerator(options)
|
||||
.then(function() {
|
||||
var generator = new generators[options.generator](options);
|
||||
|
||||
return generator.loadPlugins()
|
||||
.then(_.constant(generator));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
var generate = function(options) {
|
||||
// Set defaults to options
|
||||
options = _.defaults(options || {}, {
|
||||
// Folders to use
|
||||
input: null,
|
||||
output: null,
|
||||
"input": null,
|
||||
"output": null,
|
||||
|
||||
// Config file (relative to input)
|
||||
"configFile": "book",
|
||||
|
||||
// Output generator
|
||||
generator: "site",
|
||||
"generator": "site",
|
||||
|
||||
// Book title, keyword, description
|
||||
title: null,
|
||||
description: null,
|
||||
"title": null,
|
||||
"description": null,
|
||||
|
||||
// Origin github repository id
|
||||
github: null,
|
||||
githubHost: 'https://github.com/',
|
||||
"github": null,
|
||||
"githubHost": 'https://github.com/',
|
||||
|
||||
// Theming
|
||||
theme: path.resolve(__dirname, '../../theme')
|
||||
"theme": path.resolve(__dirname, '../../theme'),
|
||||
|
||||
// Plugins
|
||||
"plugins": [],
|
||||
"pluginsConfig": {},
|
||||
"defaultsPlugins": [], // Default plugins that can't be set in book.json
|
||||
|
||||
// Links
|
||||
"links": {
|
||||
"about": null,
|
||||
"issues": null,
|
||||
"contribue": null,
|
||||
}
|
||||
});
|
||||
|
||||
// Validate options
|
||||
if (!options.input) {
|
||||
return Q.reject(new Error("Need option input (book input directory)"));
|
||||
}
|
||||
|
||||
if (!generators[options.generator]) {
|
||||
return Q.reject(new Error("Invalid generator (availables are: "+_.keys(generators).join(", ")));
|
||||
}
|
||||
// Check files to get folder type (book, multilanguage book or neither)
|
||||
return checkGenerator(options)
|
||||
|
||||
// Read config file
|
||||
.then(function() {
|
||||
try {
|
||||
var _config = require(path.resolve(options.input, options.configFile));
|
||||
|
||||
_.extend(options, _.omit(_config, 'input', 'configFile', 'defaultsPlugins'));
|
||||
}
|
||||
catch(err) {
|
||||
// No config file: not a big deal
|
||||
return Q();
|
||||
}
|
||||
})
|
||||
|
||||
// Read readme
|
||||
.then(function() {
|
||||
return fs.readFile(path.join(options.input, "README.md"), "utf-8")
|
||||
.then(function(_readme) {
|
||||
_readme = parse.readme(_readme);
|
||||
|
||||
options.title = options.title || _readme.title;
|
||||
options.description = options.description || _readme.description || defaultDescription;
|
||||
});
|
||||
})
|
||||
|
||||
// Detect multi-languages book
|
||||
.then(function() {
|
||||
return containsFiles(options.input, ['LANGS.md'])
|
||||
})
|
||||
|
||||
.then(function(isMultiLang) {
|
||||
// Multi language book
|
||||
if(isMultiLang) {
|
||||
return generateMultiLang(options);
|
||||
}
|
||||
|
||||
// Book
|
||||
return generateBook(options);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var generateMultiLang = function(options) {
|
||||
var langsSummary;
|
||||
options.output = options.output || path.join(options.input, "_book");
|
||||
|
||||
return checkGenerator(options)
|
||||
|
||||
// Multi-languages book
|
||||
.then(function() {
|
||||
return fs.readFile(path.join(options.input, "LANGS.md"), "utf-8")
|
||||
})
|
||||
|
||||
// Clean output folder
|
||||
.then(function(_langsSummary) {
|
||||
langsSummary = _langsSummary;
|
||||
return fs.remove(options.output);
|
||||
})
|
||||
.then(function() {
|
||||
return fs.mkdirp(options.output);
|
||||
})
|
||||
|
||||
// Generate sub-books
|
||||
.then(function() {
|
||||
options.langsSummary = parse.langs(langsSummary);
|
||||
|
||||
// Generated a book for each valid entry
|
||||
return _.reduce(options.langsSummary.list, function(prev, entry) {
|
||||
return prev.then(function() {
|
||||
return generate(_.extend({}, options, {
|
||||
input: path.join(options.input, entry.path),
|
||||
output: path.join(options.output, entry.path),
|
||||
originalInput: options.input,
|
||||
originalOutput: options.output
|
||||
}));
|
||||
})
|
||||
}, Q());
|
||||
})
|
||||
|
||||
.then(function() {
|
||||
return loadGenerator(options);
|
||||
})
|
||||
|
||||
// Generate languages index
|
||||
.then(function(generator) {
|
||||
return generator.langsIndex(options.langsSummary);
|
||||
})
|
||||
|
||||
// Copy cover file
|
||||
.then(function() {
|
||||
return Q.all([
|
||||
fs.copy(path.join(options.input, "cover.jpg"), path.join(options.output, "cover.jpg")),
|
||||
fs.copy(path.join(options.input, "cover_small.jpg"), path.join(options.output, "cover_small.jpg"))
|
||||
])
|
||||
.fail(function() {
|
||||
return Q();
|
||||
})
|
||||
})
|
||||
|
||||
// Return options to caller
|
||||
.then(_.constant(options));
|
||||
};
|
||||
|
||||
/*
|
||||
* Use a specific generator to convert a gitbook to a site/pdf/ebook/
|
||||
* output is always a folder
|
||||
*/
|
||||
var generateBook = function(options) {
|
||||
var files;
|
||||
|
||||
options.output = options.output || path.join(options.input, "_book");
|
||||
|
||||
// Check if it's a book
|
||||
return containsFiles(options.input, ['SUMMARY.md', 'README.md'])
|
||||
|
||||
// Fail if not a book
|
||||
.then(function(isBook) {
|
||||
if(!isBook) {
|
||||
return Q.reject(new Error("Invalid gitbook repository, need SUMMARY.md and README.md"));
|
||||
}
|
||||
})
|
||||
|
||||
// Clean output folder
|
||||
return fs.remove(options.output)
|
||||
.then(function() {
|
||||
return fs.remove(options.output);
|
||||
})
|
||||
|
||||
// Get repo's URL
|
||||
.then(function() {
|
||||
// Git deactivated
|
||||
if(options.github === false) {
|
||||
options.github = null;
|
||||
return null;
|
||||
} else if(options.github) {
|
||||
// Git already specified in options
|
||||
options.github = (
|
||||
// Support URLs in "github" entry of book.json
|
||||
parse.git.githubID(options.github) ||
|
||||
|
||||
// Fallback
|
||||
options.github
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Try auto detecting
|
||||
return parse.git.url(options.input)
|
||||
.then(function(_url) {
|
||||
// Get ID of repo
|
||||
return parse.git.githubID(_url);
|
||||
}, function(err) {
|
||||
return null;
|
||||
})
|
||||
.then(function(repoId) {
|
||||
options.github = repoId;
|
||||
});
|
||||
})
|
||||
|
||||
.then(function() {
|
||||
return fs.mkdirp(options.output);
|
||||
@@ -67,104 +257,85 @@ var generate = function(options) {
|
||||
return fs.list(options.input)
|
||||
.then(function(_files) {
|
||||
files = _files;
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
// Create the generator
|
||||
.then(function() {
|
||||
generator = new generators[options.generator](options);
|
||||
return loadGenerator(options);
|
||||
})
|
||||
|
||||
// Detect multi-languages book
|
||||
.then(function() {
|
||||
if (_.contains(files, "LANGS.md")) {
|
||||
// Multi-languages book
|
||||
return fs.readFile(path.join(options.input, "LANGS.md"), "utf-8")
|
||||
// Convert files
|
||||
.then(function(generator) {
|
||||
// Generate the book
|
||||
return Q()
|
||||
|
||||
// Generate sub-books
|
||||
.then(function(_langsSummary) {
|
||||
options.langsSummary = parse.langs(_langsSummary);
|
||||
// Get summary
|
||||
.then(function() {
|
||||
var summary = {
|
||||
path: path.join(options.input, "SUMMARY.md")
|
||||
};
|
||||
|
||||
// Generated a book for each valid entry
|
||||
return Q.all(
|
||||
_.map(options.langsSummary.list, function(entry) {
|
||||
return generate(_.extend({}, options, {
|
||||
input: path.join(options.input, entry.path),
|
||||
output: path.join(options.output, entry.path)
|
||||
}));
|
||||
})
|
||||
);
|
||||
})
|
||||
|
||||
// Generate languages index
|
||||
.then(function() {
|
||||
return generator.langsIndex(options.langsSummary);
|
||||
});
|
||||
} else if (!_.contains(files, "SUMMARY.md") || !_.contains(files, "README.md")) {
|
||||
// Invalid book
|
||||
return Q.reject(new Error("Invalid gitbook repository, need SUMMARY.md and README.md"));
|
||||
} else {
|
||||
// Generate the book
|
||||
return Q()
|
||||
|
||||
// Read readme
|
||||
.then(function() {
|
||||
return fs.readFile(path.join(options.input, "README.md"), "utf-8")
|
||||
.then(function(_readme) {
|
||||
_readme = parse.readme(_readme);
|
||||
|
||||
options.title = options.title || _readme.title;
|
||||
options.description = options.description || _readme.description || defaultDescription;
|
||||
});
|
||||
})
|
||||
|
||||
// Get summary
|
||||
.then(function() {
|
||||
return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
|
||||
var _callHook = function(name) {
|
||||
return generator.callHook(name, summary)
|
||||
.then(function(_summary) {
|
||||
options.summary = parse.summary(_summary);
|
||||
summary = _summary;
|
||||
return summary;
|
||||
});
|
||||
};
|
||||
|
||||
// Parse navigation
|
||||
return fs.readFile(summary.path, "utf-8")
|
||||
.then(function(_content) {
|
||||
summary.content = _content;
|
||||
return _callHook("summary:before");
|
||||
})
|
||||
.then(function() {
|
||||
summary.content = parse.summary(summary.content);
|
||||
return _callHook("summary:after");
|
||||
})
|
||||
.then(function() {
|
||||
options.summary = summary.content;
|
||||
options.navigation = parse.navigation(options.summary);
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Skip processing some files
|
||||
.then(function() {
|
||||
files = _.filter(files, function (file) {
|
||||
return !(
|
||||
file === 'SUMMARY.md'
|
||||
);
|
||||
});
|
||||
})
|
||||
|
||||
// Copy file and replace markdown file
|
||||
.then(function() {
|
||||
return Q.all(
|
||||
_.chain(files)
|
||||
.map(function(file) {
|
||||
if (!file) return;
|
||||
|
||||
if (file[file.length -1] == "/") {
|
||||
return Q(generator.transferFolder(file));
|
||||
} else if (path.extname(file) == ".md" && options.navigation[file] != null) {
|
||||
return fs.readFile(path.join(options.input, file), "utf-8")
|
||||
.then(function(content) {
|
||||
return Q(generator.convertFile(content, file));
|
||||
});
|
||||
} else {
|
||||
return Q(generator.transferFile(file));
|
||||
}
|
||||
})
|
||||
.value()
|
||||
// Skip processing some files
|
||||
.then(function() {
|
||||
files = _.filter(files, function (file) {
|
||||
return !(
|
||||
file === 'SUMMARY.md'
|
||||
);
|
||||
})
|
||||
|
||||
// Finish gneration
|
||||
.then(function() {
|
||||
return generator.finish();
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
// Copy file and replace markdown file
|
||||
.then(function() {
|
||||
return Q.all(
|
||||
_.chain(files)
|
||||
.map(function(file) {
|
||||
if (!file) return;
|
||||
|
||||
if (file[file.length -1] == "/") {
|
||||
return Q(generator.transferFolder(file));
|
||||
} else if (path.extname(file) == ".md" && options.navigation[file] != null) {
|
||||
return fs.readFile(path.join(options.input, file), "utf-8")
|
||||
.then(function(content) {
|
||||
return Q(generator.convertFile(content, file));
|
||||
});
|
||||
} else {
|
||||
return Q(generator.transferFile(file));
|
||||
}
|
||||
})
|
||||
.value()
|
||||
);
|
||||
})
|
||||
|
||||
// Finish generation
|
||||
.then(function() {
|
||||
return generator.finish();
|
||||
})
|
||||
.then(function() {
|
||||
return generator.callHook("finish");
|
||||
});
|
||||
})
|
||||
|
||||
// Return all options
|
||||
@@ -234,5 +405,7 @@ var generateFile = function(options) {
|
||||
module.exports = {
|
||||
generators: generators,
|
||||
folder: generate,
|
||||
file: generateFile
|
||||
file: generateFile,
|
||||
book: generateBook,
|
||||
Plugin: Plugin,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var util = require("util");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
|
||||
var fs = require("../fs");
|
||||
var parse = require("../../parse");
|
||||
@@ -40,6 +41,35 @@ Generator.prototype.convertFile = function(content, input) {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate languages index
|
||||
// Contains the first languages readme and langs infos
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
var that = this;
|
||||
|
||||
if (langs.list.length == 0) return Q.reject("Need at least one language");
|
||||
|
||||
var mainLang = _.first(langs.list).lang;
|
||||
console.log("Main language is", mainLang);
|
||||
|
||||
return Q()
|
||||
.then(function() {
|
||||
return fs.readFile(
|
||||
path.join(that.options.output, mainLang, "README.json")
|
||||
);
|
||||
})
|
||||
.then(function(content) {
|
||||
var json = JSON.parse(content);
|
||||
_.extend(json, {
|
||||
langs: langs.list
|
||||
});
|
||||
|
||||
return fs.writeFile(
|
||||
path.join(that.options.output, "README.json"),
|
||||
JSON.stringify(json, null, 4)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
Generator.prototype.finish = function() {
|
||||
// ignore
|
||||
};
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var Q = require('q');
|
||||
|
||||
var fs = require("./fs");
|
||||
|
||||
var extsToIgnore = [".gz"]
|
||||
|
||||
var Manifest = function() {
|
||||
this.revision = 0;
|
||||
this.clear(Date.now());
|
||||
};
|
||||
|
||||
// Regenerate manifest
|
||||
Manifest.prototype.clear = function(revision) {
|
||||
if (revision) this.revision = revision;
|
||||
this.sections = {
|
||||
'CACHE': {},
|
||||
'NETWORK': {},
|
||||
'FALLBACK': {}
|
||||
};
|
||||
return Q(this);
|
||||
};
|
||||
|
||||
// Add a resource
|
||||
Manifest.prototype.add = function(category, resource, value) {
|
||||
if (_.isArray(resource)) {
|
||||
_.each(resource, function(subres) {
|
||||
this.add(category, subres, value);
|
||||
}, this);
|
||||
return;
|
||||
}
|
||||
this.sections[category][resource] = value;
|
||||
};
|
||||
|
||||
// Add a directory in cache
|
||||
Manifest.prototype.addFolder = function(folder, root, except) {
|
||||
var that = this;
|
||||
root = root || "/";
|
||||
|
||||
return fs.list(folder)
|
||||
.then(function(files) {
|
||||
_.each(
|
||||
// Ignore diretcories
|
||||
_.filter(files, function(file) {
|
||||
return file.substr(-1) != "/" && !_.contains(except, path.join(root, file)) && !_.contains(extsToIgnore, path.extname(file));
|
||||
}),
|
||||
function(file) {
|
||||
that.add("CACHE", path.join(root, file));
|
||||
}
|
||||
);
|
||||
})
|
||||
};
|
||||
|
||||
// Get manifest content
|
||||
Manifest.prototype.dump = function() {
|
||||
var lines = [
|
||||
"CACHE MANIFEST",
|
||||
"# Revision "+this.revision
|
||||
];
|
||||
|
||||
_.each(this.sections, function(content, section) {
|
||||
if (_.size(content) == 0) return;
|
||||
lines.push("");
|
||||
lines.push(section+":");
|
||||
lines = lines.concat(_.keys(content));
|
||||
}, this);
|
||||
|
||||
return Q(lines.join("\n"));
|
||||
};
|
||||
|
||||
module.exports = Manifest;
|
||||
+22
-14
@@ -2,22 +2,12 @@ var _ = require("lodash");
|
||||
var util = require("util");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var swig = require('swig');
|
||||
var hljs = require('highlight.js');
|
||||
var swig = require("../template");
|
||||
|
||||
var fs = require("../fs");
|
||||
var parse = require("../../parse");
|
||||
var BaseGenerator = require("../site");
|
||||
|
||||
// Swig filter: highlight coloration
|
||||
swig.setFilter('code', function(code, lang) {
|
||||
try {
|
||||
return hljs.highlight(lang, code).value;
|
||||
} catch(e) {
|
||||
return hljs.highlightAuto(code).value;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* This generator will generate a simple index.html which can be converted as a PDF
|
||||
@@ -25,14 +15,18 @@ swig.setFilter('code', function(code, lang) {
|
||||
var Generator = function() {
|
||||
BaseGenerator.apply(this, arguments);
|
||||
|
||||
// Load base template
|
||||
this.template = swig.compileFile(path.resolve(this.options.theme, 'templates/page.html'));
|
||||
|
||||
// List of pages content
|
||||
this.pages = {};
|
||||
};
|
||||
util.inherits(Generator, BaseGenerator);
|
||||
|
||||
// Load all templates
|
||||
Generator.prototype.loadTemplates = function() {
|
||||
this.template = swig.compileFile(
|
||||
this.plugins.template("page") || path.resolve(this.options.theme, 'templates/page.html')
|
||||
);
|
||||
};
|
||||
|
||||
Generator.prototype.convertFile = function(content, input) {
|
||||
var that = this;
|
||||
var json = {
|
||||
@@ -46,6 +40,7 @@ Generator.prototype.convertFile = function(content, input) {
|
||||
repo: that.options.githubId,
|
||||
dir: path.dirname(input) || '/',
|
||||
outdir: './',
|
||||
singleFile: true
|
||||
});
|
||||
})
|
||||
.then(function(sections) {
|
||||
@@ -56,22 +51,35 @@ Generator.prototype.convertFile = function(content, input) {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate languages index
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
return Q();
|
||||
};
|
||||
|
||||
Generator.prototype.finish = function() {
|
||||
var that = this;
|
||||
var basePath = ".";
|
||||
var output = path.join(this.options.output, "index.html");
|
||||
|
||||
var progress = parse.progress(this.options.navigation, "README.md");
|
||||
|
||||
return Q()
|
||||
// Generate html
|
||||
.then(function(pages) {
|
||||
return that._writeTemplate(that.template, {
|
||||
pages: that.pages,
|
||||
progress: progress,
|
||||
|
||||
basePath: basePath,
|
||||
staticBase: path.join(basePath, "gitbook"),
|
||||
}, output);
|
||||
})
|
||||
|
||||
// Copy cover
|
||||
.then(function() {
|
||||
return that.copyCover();
|
||||
})
|
||||
|
||||
// Copy assets
|
||||
.then(function() {
|
||||
return fs.copy(
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
var util = require("util");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var fs = require("../fs");
|
||||
var parse = require("../../parse");
|
||||
var BaseGenerator = require("../page");
|
||||
|
||||
/*
|
||||
* This generator inherits from the single page generator
|
||||
* and convert the page output to pdf using gitbook-pdf
|
||||
*/
|
||||
var Generator = function() {
|
||||
BaseGenerator.apply(this, arguments);
|
||||
|
||||
// Options for PDF generation
|
||||
this.options = _.defaults(this.options, {
|
||||
paperformat: "A4"
|
||||
});
|
||||
};
|
||||
util.inherits(Generator, BaseGenerator);
|
||||
|
||||
Generator.prototype.finish = function() {
|
||||
var that = this;
|
||||
|
||||
return BaseGenerator.prototype.finish.apply(this)
|
||||
.then(function() {
|
||||
var d = Q.defer();
|
||||
|
||||
var command = [
|
||||
"gitbook-pdf",
|
||||
"generate",
|
||||
path.join(that.options.output, "index.html"),
|
||||
path.join(that.options.output, "index.pdf"),
|
||||
"--format="+that.options.paperformat
|
||||
].join(" ");
|
||||
|
||||
exec(command, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
if (error.code == 127) {
|
||||
error.message = "Need to install gitbook-pdf using: npm install gitbook-pdf -g";
|
||||
} else {
|
||||
error.message = error.message + " "+stdout;
|
||||
}
|
||||
return d.reject(error);
|
||||
}
|
||||
d.resolve();
|
||||
});
|
||||
|
||||
return d.promise;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Generator;
|
||||
@@ -0,0 +1,207 @@
|
||||
var _ = require("lodash");
|
||||
var Q = require("q");
|
||||
var semver = require("semver");
|
||||
var path = require("path");
|
||||
var url = require("url");
|
||||
var fs = require("./fs");
|
||||
var resolve = require('resolve');
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
|
||||
var RESOURCES = ["js", "css"];
|
||||
|
||||
var Plugin = function(name, root) {
|
||||
this.name = name;
|
||||
this.root = root;
|
||||
this.packageInfos = {};
|
||||
this.infos = {};
|
||||
|
||||
_.each([
|
||||
"gitbook-plugin-"+name,
|
||||
"gitbook-theme-"+name,
|
||||
"gitbook-"+name,
|
||||
name,
|
||||
], function(_name) {
|
||||
if (this.load(_name, __dirname)) return false;
|
||||
if (this.load(_name, path.resolve(root))) return false;
|
||||
}, this);
|
||||
};
|
||||
|
||||
// Load from a name
|
||||
Plugin.prototype.load = function(name, baseDir) {
|
||||
try {
|
||||
var res = resolve.sync(name+"/package.json", { basedir: baseDir });
|
||||
|
||||
this.baseDir = path.dirname(res);
|
||||
this.packageInfos = require(res);
|
||||
this.infos = require(resolve.sync(name, { basedir: baseDir }));
|
||||
this.name = name;
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Return resources
|
||||
Plugin.prototype.getResources = function(resource) {
|
||||
if (!this.infos.book || !this.infos.book[resource]) {
|
||||
return [];
|
||||
}
|
||||
return _.chain(this.infos.book[resource])
|
||||
.map(function(resource) {
|
||||
var parsed = url.parse(resource);
|
||||
if (parsed.protocol) return {"url": resource}
|
||||
else return { "path": this.name+"/"+resource };
|
||||
}.bind(this))
|
||||
.value();
|
||||
};
|
||||
|
||||
// Test if it's a valid plugin
|
||||
Plugin.prototype.isValid = function() {
|
||||
return (
|
||||
this.packageInfos
|
||||
&& this.packageInfos.name
|
||||
&& this.packageInfos.engines
|
||||
&& this.packageInfos.engines.gitbook
|
||||
&& semver.satisfies(pkg.version, this.packageInfos.engines.gitbook)
|
||||
);
|
||||
};
|
||||
|
||||
// Resolve file path
|
||||
Plugin.prototype.resolveFile = function(filename) {
|
||||
return path.resolve(this.baseDir, filename);
|
||||
};
|
||||
|
||||
// Resolve file path
|
||||
Plugin.prototype.callHook = function(name, context, data) {
|
||||
var hookFunc = this.infos.hooks? this.infos.hooks[name] : null;
|
||||
data = data || {};
|
||||
|
||||
if (!hookFunc) return Q(data);
|
||||
|
||||
return Q()
|
||||
.then(function() {
|
||||
return hookFunc.apply(context, [data]);
|
||||
});
|
||||
};
|
||||
|
||||
// Has assets
|
||||
Plugin.prototype.hasAssets = function(out) {
|
||||
return (this.infos.book && this.infos.book.assets);
|
||||
};
|
||||
|
||||
// Copy plugin assets fodler
|
||||
Plugin.prototype.copyAssets = function(out) {
|
||||
if (!this.hasAssets()) return Q();
|
||||
return fs.copy(
|
||||
this.resolveFile(this.infos.book.assets),
|
||||
out
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Normalize a list of plugin name to use
|
||||
Plugin.normalizeNames = function(names) {
|
||||
// Normalize list to an array
|
||||
names = _.isString(names) ? names.split(",") : (names || []);
|
||||
|
||||
// List plugins to remove
|
||||
var toremove = _.chain(names)
|
||||
.filter(function(name) {
|
||||
return name.length > 0 && name[0] == "-";
|
||||
})
|
||||
.map(function(name) {
|
||||
return name.slice(1)
|
||||
})
|
||||
.value();
|
||||
|
||||
// Merge with defaults
|
||||
names = _.chain(names)
|
||||
.concat(Plugin.defaults)
|
||||
.uniq()
|
||||
.value();
|
||||
|
||||
// Remove plugins starting with
|
||||
names = _.filter(names, function(name) {
|
||||
return !_.contains(toremove, name) && !(name.length > 0 && name[0] == "-");
|
||||
});
|
||||
|
||||
return names;
|
||||
};
|
||||
|
||||
// Extract data from a list of plugin
|
||||
Plugin.fromList = function(names, root) {
|
||||
var failed = [];
|
||||
|
||||
// Load plugins
|
||||
var plugins = _.map(names, function(name) {
|
||||
var plugin = new Plugin(name, root);
|
||||
if (!plugin.isValid()) failed.push(name);
|
||||
return plugin;
|
||||
});
|
||||
|
||||
if (_.size(failed) > 0) return Q.reject(new Error("Error loading plugins: "+failed.join(",")));
|
||||
|
||||
// Get all resources
|
||||
var resources = _.chain(RESOURCES)
|
||||
.map(function(resource) {
|
||||
return [
|
||||
resource,
|
||||
_.chain(plugins)
|
||||
.map(function(plugin) {
|
||||
return plugin.getResources(resource);
|
||||
})
|
||||
.flatten()
|
||||
.value()
|
||||
];
|
||||
})
|
||||
.object()
|
||||
.value();
|
||||
resources.html = {}
|
||||
|
||||
_.each(plugins, function(plugin) {
|
||||
if (!plugin.infos.book || !plugin.infos.book.html) return;
|
||||
var html = plugin.infos.book.html || {};
|
||||
_.each(html, function(code, key) {
|
||||
if (!_.isFunction(code)) code = _.constant(code);
|
||||
if (!resources.html[key]) resources.html[key] = [];
|
||||
resources.html[key].push(code);
|
||||
})
|
||||
});
|
||||
|
||||
return Q({
|
||||
'list': plugins,
|
||||
'resources': resources,
|
||||
'hook': function(name, context, data) {
|
||||
return _.reduce(plugins, function(prev, plugin) {
|
||||
return prev.then(function(ret) {
|
||||
return plugin.callHook(name, context, ret);
|
||||
})
|
||||
}, Q(data));
|
||||
},
|
||||
'template': function(name) {
|
||||
var withTpl = _.find(plugins, function(plugin) {
|
||||
return (plugin.infos.templates
|
||||
&& plugin.infos.templates[name]);
|
||||
});
|
||||
|
||||
if (!withTpl) return null;
|
||||
return withTpl.resolveFile(withTpl.infos.templates[name]);
|
||||
},
|
||||
'html': function(tag, context, options) {
|
||||
return _.map(resources.html[tag] || [], function(code) {
|
||||
return code.call(context, options);
|
||||
}).join("\n");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Default plugins
|
||||
Plugin.defaults = [
|
||||
"mathjax"
|
||||
];
|
||||
|
||||
module.exports = Plugin;
|
||||
+112
-26
@@ -2,25 +2,16 @@ var util = require("util");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
var swig = require('swig');
|
||||
var swig = require("../template");
|
||||
|
||||
var fs = require("../fs");
|
||||
var parse = require("../../parse");
|
||||
var BaseGenerator = require("../generator");
|
||||
|
||||
var links = require("../../utils/links");
|
||||
var indexer = require('./search_indexer');
|
||||
var Manifest = require('../manifest');
|
||||
|
||||
// Swig filter for returning the count of lines in a code section
|
||||
swig.setFilter('lines', function(content) {
|
||||
return content.split('\n').length;
|
||||
});
|
||||
|
||||
// Swig filter for returning a link to the associated html file of a markdown file
|
||||
swig.setFilter('mdLink', function(link) {
|
||||
var link = link.replace(".md", ".html");
|
||||
if (link == "README.html") link = "index.html";
|
||||
return link;
|
||||
});
|
||||
|
||||
var Generator = function() {
|
||||
BaseGenerator.apply(this, arguments);
|
||||
@@ -30,17 +21,38 @@ var Generator = function() {
|
||||
|
||||
this.revision = Date.now();
|
||||
this.indexer = indexer();
|
||||
|
||||
// Load base template
|
||||
this.template = swig.compileFile(path.resolve(this.options.theme, 'templates/site.html'));
|
||||
this.langsTemplate = swig.compileFile(path.resolve(this.options.theme, 'templates/langs.html'));
|
||||
this.manifest = new Manifest(Date.now());
|
||||
this.manifest.add("NETWORK", [
|
||||
'*'
|
||||
]);
|
||||
};
|
||||
util.inherits(Generator, BaseGenerator);
|
||||
|
||||
// Load all templates
|
||||
Generator.prototype.loadTemplates = function() {
|
||||
this.template = swig.compileFile(
|
||||
this.plugins.template("site") || path.resolve(this.options.theme, 'templates/site.html')
|
||||
);
|
||||
this.langsTemplate = swig.compileFile(
|
||||
this.plugins.template("langs") || path.resolve(this.options.theme, 'templates/langs.html')
|
||||
);
|
||||
};
|
||||
|
||||
// Load plugins
|
||||
Generator.prototype.loadPlugins = function() {
|
||||
var that = this;
|
||||
|
||||
return BaseGenerator.prototype.loadPlugins.apply(this)
|
||||
.then(function() {
|
||||
return that.loadTemplates();
|
||||
});
|
||||
};
|
||||
|
||||
// Generate a template
|
||||
Generator.prototype._writeTemplate = function(tpl, options, output) {
|
||||
Generator.prototype._writeTemplate = function(tpl, options, output, interpolate) {
|
||||
var that = this;
|
||||
|
||||
interpolate = interpolate || _.identity;
|
||||
return Q()
|
||||
.then(function(sections) {
|
||||
return tpl(_.extend({
|
||||
@@ -54,9 +66,16 @@ Generator.prototype._writeTemplate = function(tpl, options, output) {
|
||||
githubHost: that.options.githubHost,
|
||||
|
||||
summary: that.options.summary,
|
||||
allNavigation: that.options.navigation
|
||||
allNavigation: that.options.navigation,
|
||||
|
||||
plugins: that.plugins,
|
||||
pluginsConfig: JSON.stringify(that.options.pluginsConfig),
|
||||
htmlSnippet: _.partialRight(that.plugins.html, that, options),
|
||||
|
||||
options: that.options
|
||||
}, options));
|
||||
})
|
||||
.then(interpolate)
|
||||
.then(function(html) {
|
||||
return fs.writeFile(
|
||||
output,
|
||||
@@ -73,7 +92,6 @@ Generator.prototype.indexPage = function(lexed, pagePath) {
|
||||
// Convert a markdown file to html
|
||||
Generator.prototype.convertFile = function(content, _input) {
|
||||
var that = this;
|
||||
var progress = parse.progress(this.options.navigation, _input);
|
||||
|
||||
_output = _input.replace(".md", ".html");
|
||||
if (_output == "README.html") _output = "index.html";
|
||||
@@ -82,10 +100,29 @@ Generator.prototype.convertFile = function(content, _input) {
|
||||
var output = path.join(this.options.output, _output);
|
||||
var basePath = path.relative(path.dirname(output), this.options.output) || ".";
|
||||
|
||||
var page = {
|
||||
path: _input,
|
||||
rawPath: input, // path to raw md file
|
||||
content: content,
|
||||
progress: parse.progress(this.options.navigation, _input)
|
||||
};
|
||||
|
||||
var _callHook = function(name) {
|
||||
return that.callHook(name, page)
|
||||
.then(function(_page) {
|
||||
page = _page;
|
||||
return page;
|
||||
});
|
||||
};
|
||||
|
||||
return Q()
|
||||
.then(function() {
|
||||
// Send content to plugins
|
||||
return _callHook("page:before");
|
||||
})
|
||||
.then(function() {
|
||||
// Lex page
|
||||
return parse.lex(content);
|
||||
return parse.lex(page.content);
|
||||
})
|
||||
.then(function(lexed) {
|
||||
// Index page in search
|
||||
@@ -101,15 +138,27 @@ Generator.prototype.convertFile = function(content, _input) {
|
||||
});
|
||||
})
|
||||
.then(function(sections) {
|
||||
page.sections = sections;
|
||||
|
||||
// Use plugin hook
|
||||
return _callHook("page");
|
||||
})
|
||||
.then(function() {
|
||||
that.manifest.add("CACHE", _output);
|
||||
|
||||
return that._writeTemplate(that.template, {
|
||||
progress: progress,
|
||||
progress: page.progress,
|
||||
|
||||
_input: _input,
|
||||
content: sections,
|
||||
content: page.sections,
|
||||
|
||||
basePath: basePath,
|
||||
staticBase: path.join(basePath, "gitbook"),
|
||||
}, output);
|
||||
staticBase: links.join(basePath, "gitbook"),
|
||||
}, output, function(html) {
|
||||
page.content = html;
|
||||
|
||||
return _callHook("page:after").get("content")
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -134,10 +183,31 @@ Generator.prototype.langsIndex = function(langs) {
|
||||
Generator.prototype.copyAssets = function() {
|
||||
var that = this;
|
||||
|
||||
// Copy gitbook assets
|
||||
return fs.copy(
|
||||
path.join(that.options.theme, "assets"),
|
||||
path.join(that.options.output, "gitbook")
|
||||
);
|
||||
)
|
||||
|
||||
// Add to cache manifest
|
||||
.then(function() {
|
||||
return that.manifest.addFolder(path.join(that.options.output, "gitbook"), "gitbook");
|
||||
})
|
||||
|
||||
// Copy plugins assets
|
||||
.then(function() {
|
||||
return Q.all(
|
||||
_.map(that.plugins.list, function(plugin) {
|
||||
if (!plugin.hasAssets()) return Q();
|
||||
|
||||
var pluginAssets = path.join(that.options.output, "gitbook/plugins/", plugin.name);
|
||||
return plugin.copyAssets(pluginAssets)
|
||||
.then(function() {
|
||||
return that.manifest.addFolder(pluginAssets, "gitbook/plugins/"+plugin.name);
|
||||
});
|
||||
})
|
||||
);
|
||||
})
|
||||
};
|
||||
|
||||
// Dump search index to disk
|
||||
@@ -148,9 +218,25 @@ Generator.prototype.writeSearchIndex = function() {
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// Add cache manifest
|
||||
Generator.prototype.writeCacheManifest = function() {
|
||||
return fs.writeFile(
|
||||
path.join(this.options.output, 'manifest.appcache'),
|
||||
this.manifest.dump()
|
||||
);
|
||||
};
|
||||
|
||||
Generator.prototype.finish = function() {
|
||||
return this.copyAssets()
|
||||
var deferred = this.copyAssets()
|
||||
.then(this.copyCover)
|
||||
.then(this.writeSearchIndex);
|
||||
|
||||
if (this.options.cache !== false) {
|
||||
deferred = deferred.then(this.writeCacheManifest);
|
||||
}
|
||||
|
||||
return deferred;
|
||||
};
|
||||
|
||||
module.exports = Generator;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
var path = require("path");
|
||||
var swig = require('swig');
|
||||
var hljs = require('highlight.js');
|
||||
|
||||
var links = require('../utils/').links;
|
||||
var pkg = require('../../package.json');
|
||||
|
||||
swig.setDefaults({
|
||||
locals: {
|
||||
gitbook: {
|
||||
version: pkg.version
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Swig filter for returning the count of lines in a code section
|
||||
swig.setFilter('lines', function(content) {
|
||||
return content.split('\n').length;
|
||||
});
|
||||
|
||||
// Swig filter for returning a link to the associated html file of a markdown file
|
||||
swig.setFilter('mdLink', function(link) {
|
||||
var link = link.replace(".md", ".html");
|
||||
if (link == "README.html") link = "index.html";
|
||||
return link;
|
||||
});
|
||||
|
||||
// Swig filter: highlight coloration
|
||||
swig.setFilter('code', function(code, lang) {
|
||||
try {
|
||||
return hljs.highlight(lang, code).value;
|
||||
} catch(e) {
|
||||
return hljs.highlightAuto(code).value;
|
||||
}
|
||||
});
|
||||
|
||||
// Convert a level into a deep level
|
||||
swig.setFilter('lvl', function(lvl) {
|
||||
return lvl.split(".").length;
|
||||
});
|
||||
|
||||
// Join path
|
||||
swig.setFilter('pathJoin', function(base, _path) {
|
||||
return path.join(base, _path);
|
||||
});
|
||||
|
||||
// Is a link an absolute link
|
||||
swig.setFilter('isExternalLink', function(link) {
|
||||
return links.isExternal(link);
|
||||
});
|
||||
|
||||
module.exports = swig;
|
||||
@@ -0,0 +1,20 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
module.exports = function(code, folder) {
|
||||
folder = folder || '';
|
||||
|
||||
return code.replace(/{{([\s\S]+?)}}/g, function(match, filename) {
|
||||
// Normalize filename
|
||||
var fname = path.join(folder, filename.trim());
|
||||
|
||||
// Try including snippet from FS
|
||||
try {
|
||||
// Trim trailing newlines/space of imported snippets
|
||||
return fs.readFileSync(fname, 'utf8').trimRight();
|
||||
} catch(err) {}
|
||||
|
||||
// If fails leave content as is
|
||||
return match;
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
var Q = require('q');
|
||||
var _ = require('lodash');
|
||||
var cp = require('child_process');
|
||||
var url = require('url');
|
||||
|
||||
// Get the remote of a given repo
|
||||
function gitURL(path) {
|
||||
var d = Q.defer();
|
||||
|
||||
cp.exec("git config --get remote.origin.url", {
|
||||
cwd: path,
|
||||
env: process.env,
|
||||
}, function(err, stdout, stderr) {
|
||||
if(err) {
|
||||
return d.reject(err);
|
||||
}
|
||||
|
||||
return d.resolve(stdout);
|
||||
});
|
||||
|
||||
return d.promise
|
||||
.then(function(output) {
|
||||
return output.replace(/(\r\n|\n|\r)/gm, "");
|
||||
});
|
||||
}
|
||||
|
||||
// Poorman's parsing
|
||||
// Parse a git URL to a github ID : username/reponame
|
||||
function githubID(_url) {
|
||||
// Remove .git if it's in _url
|
||||
var sliceEnd = _url.slice(-4) === '.git' ? -4 : undefined;
|
||||
|
||||
// Detect HTTPS repos
|
||||
var parsed = url.parse(_url);
|
||||
if(parsed.protocol === 'https:' && parsed.host === 'github.com') {
|
||||
return parsed.path.slice(1, sliceEnd);
|
||||
}
|
||||
|
||||
// Detect SSH repos
|
||||
if(_url.indexOf('git@') === 0) {
|
||||
return _url.split(':', 2)[1].slice(0, sliceEnd);
|
||||
}
|
||||
|
||||
// None found
|
||||
return null;
|
||||
}
|
||||
|
||||
function titleCase(str) {
|
||||
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
url: gitURL,
|
||||
githubID: githubID,
|
||||
titleCase: titleCase
|
||||
};
|
||||
+2
-1
@@ -5,5 +5,6 @@ module.exports = {
|
||||
lex: require('./lex'),
|
||||
progress: require('./progress'),
|
||||
navigation: require('./navigation'),
|
||||
readme: require('./readme')
|
||||
readme: require('./readme'),
|
||||
git: require('./git')
|
||||
};
|
||||
|
||||
+8
-6
@@ -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;
|
||||
@@ -118,6 +118,10 @@ function lexPage(src) {
|
||||
|
||||
return sections;
|
||||
}, [])
|
||||
.map(function(section) {
|
||||
section.links = nodes.links;
|
||||
return section;
|
||||
})
|
||||
.value();
|
||||
}
|
||||
|
||||
|
||||
+26
-51
@@ -6,6 +6,12 @@ function clean(obj) {
|
||||
return obj && _.omit(obj, ['articles']);
|
||||
}
|
||||
|
||||
function flattenChapters(chapters) {
|
||||
return _.reduce(chapters, function(accu, chapter) {
|
||||
return accu.concat([clean(chapter)].concat(flattenChapters(chapter.articles)));
|
||||
}, []);
|
||||
}
|
||||
|
||||
// Returns from a summary a map of
|
||||
/*
|
||||
{
|
||||
@@ -20,61 +26,30 @@ function navigation(summary, files) {
|
||||
// Support single files as well as list
|
||||
files = _.isArray(files) ? files : (_.isString(files) ? [files] : null);
|
||||
|
||||
// List of all navNodes
|
||||
// Flatten chapters, then add in default README node if ndeeded etc ...
|
||||
var navNodes = flattenChapters(summary.chapters);
|
||||
var prevNodes = [null].concat(navNodes.slice(0, -1));
|
||||
var nextNodes = navNodes.slice(1).concat([null]);
|
||||
|
||||
// Mapping of prev/next for a give path
|
||||
var mapping = {};
|
||||
var mapping = _.chain(_.zip(navNodes, prevNodes, nextNodes))
|
||||
.map(function(nodes) {
|
||||
var current = nodes[0], prev = nodes[1], next = nodes[2];
|
||||
|
||||
// Special README nav
|
||||
var README_NAV = {
|
||||
path: 'README.md',
|
||||
title: 'Introduction',
|
||||
};
|
||||
|
||||
// Walk the chapter/article tree and create navigation entires
|
||||
_.each(summary.chapters, function(chapter, idx, chapters) {
|
||||
// Skip if no path
|
||||
if(!chapter.path) return;
|
||||
if(!current.path) return null;
|
||||
|
||||
var currentChapter = clean(chapter);
|
||||
var prevChapter = (idx-1 < 0) ? README_NAV : chapters[idx-1];
|
||||
var nextChapter = (idx+1 >= chapters.length) ? null : chapters[idx+1];
|
||||
|
||||
var prev = (!prevChapter || _.isEmpty(prevChapter.articles)) ?
|
||||
prevChapter : _.last(prevChapter.articles);
|
||||
var next = (!chapter || _.isEmpty(chapter.articles)) ?
|
||||
nextChapter : _.first(chapter.articles);
|
||||
|
||||
// Add chapter mapping
|
||||
mapping[chapter.path] = {
|
||||
title: chapter.title,
|
||||
prev: clean(prev),
|
||||
next: clean(next),
|
||||
level: (idx+1).toString(),
|
||||
};
|
||||
|
||||
// Check a chapter's articles
|
||||
_.each(chapter.articles, function(article, _idx, articles) {
|
||||
// Skip if no path
|
||||
if(!article.path) return;
|
||||
|
||||
var prev = (_idx-1 < 0) ? currentChapter : clean(articles[_idx-1]);
|
||||
var next = (_idx+1 >= articles.length) ? nextChapter : clean(articles[_idx+1]);
|
||||
|
||||
mapping[article.path] = {
|
||||
title: article.title,
|
||||
prev: clean(prev),
|
||||
next: clean(next),
|
||||
level: [idx+1, _idx+1].join('.'),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
// Hack for README.html
|
||||
mapping['README.md'] = {
|
||||
title: README_NAV.title,
|
||||
prev: null,
|
||||
next: clean(summary.chapters[0]),
|
||||
level: '0',
|
||||
};
|
||||
return [current.path, {
|
||||
title: current.title,
|
||||
prev: prev,
|
||||
next: next,
|
||||
level: current.level,
|
||||
}];
|
||||
})
|
||||
.filter()
|
||||
.object()
|
||||
.value();
|
||||
|
||||
// Filter for only files we want
|
||||
if(files) {
|
||||
|
||||
+11
-6
@@ -5,6 +5,7 @@ var hljs = require('highlight.js');
|
||||
var lex = require('./lex');
|
||||
var renderer = require('./renderer');
|
||||
|
||||
var codeInclude = require('./code_include');
|
||||
var lnormalize = require('../utils/lang').normalize;
|
||||
|
||||
|
||||
@@ -12,10 +13,9 @@ var lnormalize = require('../utils/lang').normalize;
|
||||
// Render a section using our custom renderer
|
||||
function render(section, _options) {
|
||||
// Copy section
|
||||
var links = section.links || {};
|
||||
section = _.toArray(section);
|
||||
|
||||
// marked's Render expects this, we don't use it yet
|
||||
section.links = {};
|
||||
section.links = links;
|
||||
|
||||
// Build options using defaults and our custom renderer
|
||||
var options = _.extend({}, marked.defaults, {
|
||||
@@ -74,15 +74,20 @@ function parsePage(src, options) {
|
||||
// Main language
|
||||
var lang = validLangs ? langs[0] : null;
|
||||
|
||||
// codeInclude shortcut
|
||||
var ci = function(code) {
|
||||
return codeInclude(code, options.dir);
|
||||
};
|
||||
|
||||
return {
|
||||
id: section.id,
|
||||
type: section.type,
|
||||
content: render(nonCodeNodes),
|
||||
lang: lang,
|
||||
code: {
|
||||
base: codeNodes[0].text,
|
||||
solution: codeNodes[1].text,
|
||||
validation: codeNodes[2].text,
|
||||
base: ci(codeNodes[0].text),
|
||||
solution: ci(codeNodes[1].text),
|
||||
validation: ci(codeNodes[2].text),
|
||||
// Context is optional
|
||||
context: codeNodes[3] ? codeNodes[3].text : null,
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ var calculProgress = function(navigation, current) {
|
||||
nav.path = path;
|
||||
return nav;
|
||||
})
|
||||
.sortBy(function(nav) {
|
||||
return nav.level;
|
||||
})
|
||||
.map(function(nav, i) {
|
||||
// Calcul percent
|
||||
nav.percent = (i * 100) / Math.max((n - 1), 1);
|
||||
@@ -27,7 +24,7 @@ var calculProgress = function(navigation, current) {
|
||||
} else if (done) {
|
||||
prevPercent = nav.percent;
|
||||
}
|
||||
|
||||
|
||||
return nav;
|
||||
})
|
||||
.value();
|
||||
|
||||
+18
-5
@@ -1,5 +1,6 @@
|
||||
var _ = require('lodash');
|
||||
var marked = require('marked');
|
||||
var textRenderer = require('marked-text-renderer');
|
||||
|
||||
function extractFirstNode(nodes, nType) {
|
||||
return _.chain(nodes)
|
||||
@@ -14,16 +15,28 @@ function extractFirstNode(nodes, nType) {
|
||||
|
||||
function parseReadme(src) {
|
||||
var nodes, title, description;
|
||||
var renderer = textRenderer();
|
||||
|
||||
// Parse content
|
||||
nodes = marked.lexer(src);
|
||||
|
||||
var title = extractFirstNode(nodes, "heading");
|
||||
var description = extractFirstNode(nodes, "paragraph");
|
||||
|
||||
title = extractFirstNode(nodes, "heading") || '';
|
||||
description = extractFirstNode(nodes, "paragraph") || '';
|
||||
|
||||
var convert = _.compose(
|
||||
function(text) {
|
||||
return _.unescape(text.replace(/(\r\n|\n|\r)/gm, ""));
|
||||
},
|
||||
function(text) {
|
||||
return marked.parse(text, _.extend({}, marked.defaults, {
|
||||
renderer: renderer
|
||||
}));
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
title: title,
|
||||
description: description
|
||||
title: convert(title),
|
||||
description: convert(description)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+51
-11
@@ -1,5 +1,8 @@
|
||||
var url = require('url');
|
||||
var inherits = require('util').inherits;
|
||||
var links = require('../utils').links;
|
||||
var codeInclude = require('./code_include');
|
||||
|
||||
|
||||
var path = require('path');
|
||||
|
||||
@@ -16,6 +19,7 @@ function GitBookRenderer(options, extra_options) {
|
||||
this._extra_options = extra_options;
|
||||
this.quizRowId = 0;
|
||||
this.id = rendererId++;
|
||||
this.quizIndex = 0;
|
||||
}
|
||||
inherits(GitBookRenderer, marked.Renderer);
|
||||
|
||||
@@ -38,23 +42,38 @@ GitBookRenderer.prototype._unsanitized = function(href) {
|
||||
};
|
||||
|
||||
GitBookRenderer.prototype.link = function(href, title, text) {
|
||||
// Our "fixed" href
|
||||
var _href = href;
|
||||
|
||||
// Don't build if it looks malicious
|
||||
if (this.options.sanitize && this._unsanitized(href)) {
|
||||
return '';
|
||||
return text;
|
||||
}
|
||||
|
||||
// Parsed version of the url
|
||||
var parsed = url.parse(href);
|
||||
|
||||
var o = this._extra_options;
|
||||
|
||||
// Relative link, rewrite it to point to github repo
|
||||
if(!parsed.protocol && parsed.path && parsed.path[0] != '/' && o && o.repo && o.dir) {
|
||||
href = url.resolve('https://github.com/' + o.repo + '/blob/', [o.dir, href].join("/"));
|
||||
parsed = url.parse(href);
|
||||
if(links.isRelative(_href)) {
|
||||
if (path.extname(parsed.path) == ".md") {
|
||||
_href = links.toAbsolute(_href, o.dir || "./", o.outdir || "./");
|
||||
|
||||
if (o.singleFile) {
|
||||
_href = "#"+_href;
|
||||
} else {
|
||||
_href = _href.replace(".md", ".html");
|
||||
}
|
||||
} else if (o && o.repo && o.dir) {
|
||||
href = url.resolve('https://github.com/' + o.repo + '/blob/', [o.dir, _href].join("/"));
|
||||
parsed = url.parse(href);
|
||||
_href = parsed.href;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate HTML for link
|
||||
var out = '<a href="' + parsed.href + '"';
|
||||
var out = '<a href="' + _href + '"';
|
||||
// Title if no null
|
||||
if (title) {
|
||||
out += ' title="' + title + '"';
|
||||
@@ -78,9 +97,11 @@ GitBookRenderer.prototype.image = function(href, title, text) {
|
||||
var o = this._extra_options;
|
||||
|
||||
// Relative image, rewrite it depending output
|
||||
if(!parsed.protocol && parsed.path && parsed.path[0] != '/' && o && o.dir && o.outdir) {
|
||||
var outdir = o.outdir.charAt(o.outdir.length - 1) === '/' ? o.outdir : o.outdir + '/';
|
||||
_href = url.resolve(outdir, [o.dir, href].join('/'));
|
||||
if(links.isRelative(href) && o && o.dir && o.outdir) {
|
||||
// o.dir: directory parent of the file currently in rendering process
|
||||
// o.outdir: directory parent from the html output
|
||||
|
||||
_href = links.toAbsolute(_href, o.dir, o.outdir);
|
||||
}
|
||||
|
||||
return GitBookRenderer.super_.prototype.image.call(this, _href, title, text);
|
||||
@@ -97,11 +118,15 @@ GitBookRenderer.prototype._createCheckboxAndRadios = function(text) {
|
||||
if (!match) {
|
||||
return text;
|
||||
}
|
||||
var field = "<input name='quiz-row-" + this.id + "-" + this.quizRowId + "' type='";
|
||||
var quizIdentifier = 'quiz-row-' + this.id + '-' + this.quizRowId + '-' + this.quizIndex++;
|
||||
var field = "<input name='" + quizIdentifier + "' id='" + quizIdentifier + "' type='";
|
||||
field += match[1] === '(' ? "radio" : "checkbox";
|
||||
field += match[2] === 'x' ? "' checked/>" : "'/>";
|
||||
return text.replace(fieldRegex, field);
|
||||
}
|
||||
var splittedText = text.split(fieldRegex);
|
||||
var length = splittedText.length;
|
||||
var label = '<label class="quiz-label" for="' + quizIdentifier + '">' + splittedText[length - 1] + '</label>';
|
||||
return text.replace(fieldRegex, field).replace(splittedText[length - 1], label);
|
||||
};
|
||||
|
||||
GitBookRenderer.prototype.tablecell = function(content, flags) {
|
||||
return GitBookRenderer.super_.prototype.tablecell(this._createCheckboxAndRadios(content), flags);
|
||||
@@ -111,5 +136,20 @@ GitBookRenderer.prototype.listitem = function(text) {
|
||||
return GitBookRenderer.super_.prototype.listitem(this._createCheckboxAndRadios(text));
|
||||
};
|
||||
|
||||
GitBookRenderer.prototype.code = function(code, lang, escaped) {
|
||||
return GitBookRenderer.super_.prototype.code.call(
|
||||
this,
|
||||
// Import code snippets
|
||||
codeInclude(code, this._extra_options.dir),
|
||||
lang,
|
||||
escaped
|
||||
);
|
||||
};
|
||||
|
||||
GitBookRenderer.prototype.heading = function(text, level, raw) {
|
||||
var id = this.options.headerPrefix + raw.toLowerCase().replace(/[^\w -]+/g, '').replace(/ /g, '-');
|
||||
return '<h' + level + ' id="' + id + '">' + text + '</h' + level + '>\n';
|
||||
};
|
||||
|
||||
// Exports
|
||||
module.exports = GitBookRenderer;
|
||||
|
||||
+40
-13
@@ -82,36 +82,63 @@ function parseTitle(src, nums) {
|
||||
level: level,
|
||||
|
||||
// Replace .md references with .html
|
||||
path: matches[2],
|
||||
path: matches[2].replace(/\\/g, '/'),
|
||||
};
|
||||
}
|
||||
|
||||
function parseArticle(chapterNum, nodes, idx) {
|
||||
return parseTitle(_.first(nodes).text, [chapterNum, idx+1]);
|
||||
}
|
||||
function parseChapter(nodes, nums) {
|
||||
// Convert single number to an array
|
||||
nums = _.isArray(nums) ? nums : [nums];
|
||||
|
||||
function parseChapter(nodes, idx) {
|
||||
return _.extend(parseTitle(_.first(nodes).text, [idx+1]), {
|
||||
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle.bind(null, idx+1))
|
||||
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));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function parseSummary(src) {
|
||||
function defaultChapterList(chapterList) {
|
||||
var first = _.first(chapterList);
|
||||
|
||||
if (first) {
|
||||
var chapter = parseChapter(first, [0]);
|
||||
|
||||
// Already have README node, we're good to go
|
||||
if(chapter.path === 'README.md') {
|
||||
return chapterList;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
[ { type: 'text', text: '[Introduction](README.md)' } ]
|
||||
].concat(chapterList);
|
||||
}
|
||||
|
||||
function listGroups(src) {
|
||||
var nodes = marked.lexer(src);
|
||||
|
||||
// Get out list of chapters
|
||||
var chapterList = filterList(nodes);
|
||||
// Get out groups of lists
|
||||
return listSplit(
|
||||
filterList(nodes),
|
||||
'list_item_start', 'list_item_end'
|
||||
);
|
||||
}
|
||||
|
||||
function parseSummary(src) {
|
||||
// Split out chapter sections
|
||||
var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end'))
|
||||
.map(parseChapter)
|
||||
.value();
|
||||
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,3 +1,4 @@
|
||||
module.exports = {
|
||||
lang: require('./lang'),
|
||||
links: require('./links')
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ var MAP = {
|
||||
'py': 'python',
|
||||
'js': 'javascript',
|
||||
'rb': 'ruby',
|
||||
'csharp': 'cs',
|
||||
};
|
||||
|
||||
function normalize(lang) {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
var url = require('url');
|
||||
var path = require('path');
|
||||
|
||||
// Is the link an external link
|
||||
var isExternal = function(href) {
|
||||
try {
|
||||
return Boolean(url.parse(href).protocol);
|
||||
} catch(err) { }
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// Return true if the link is relative
|
||||
var isRelative = function(href) {
|
||||
try {
|
||||
var parsed = url.parse(href);
|
||||
|
||||
return !parsed.protocol && parsed.path && parsed.path[0] != '/';
|
||||
} catch(err) {}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Relative to absolute path
|
||||
// dir: directory parent of the file currently in rendering process
|
||||
// outdir: directory parent from the html output
|
||||
|
||||
var toAbsolute = function(_href, dir, outdir) {
|
||||
// Absolute file in source
|
||||
_href = path.join(dir, _href);
|
||||
|
||||
// make it relative to output
|
||||
_href = path.relative(outdir, _href);
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
_href = _href.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
return _href;
|
||||
};
|
||||
|
||||
// Join links
|
||||
|
||||
var join = function() {
|
||||
var _href = path.join.apply(path, arguments);
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
_href = _href.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
return _href;
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
isRelative: isRelative,
|
||||
isExternal: isExternal,
|
||||
toAbsolute: toAbsolute,
|
||||
join: join
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
var _ = require("lodash");
|
||||
|
||||
function escapeShellArg(arg) {
|
||||
var ret = '';
|
||||
|
||||
ret = arg.replace(/"/g, '\\"');
|
||||
|
||||
return "\"" + ret + "\"";
|
||||
}
|
||||
|
||||
function optionsToShellArgs(options) {
|
||||
return _.chain(options)
|
||||
.map(function(value, key) {
|
||||
if (value == null || value == false) return null;
|
||||
if (value == true) return key;
|
||||
return key+"="+escapeShellArg(value);
|
||||
})
|
||||
.compact()
|
||||
.value()
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
escapeShellArg: escapeShellArg,
|
||||
optionsToShellArgs: optionsToShellArgs
|
||||
};
|
||||
+24
-5
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "0.2.2",
|
||||
"version": "0.6.0",
|
||||
"homepage": "http://www.gitbook.io/",
|
||||
"description": "Library and cmd utility to generate GitBooks",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
@@ -15,14 +16,22 @@
|
||||
"commander": "2.2.0",
|
||||
"fs-extra": "0.8.1",
|
||||
"highlight.js": "8.0.0",
|
||||
"tmp": "0.0.23"
|
||||
"tmp": "0.0.23",
|
||||
"semver": "2.2.1",
|
||||
"gaze": "~0.5.1",
|
||||
"resolve": "0.6.3",
|
||||
"tiny-lr-fork": "0.0.5",
|
||||
"gitbook-plugin": "0.0.2",
|
||||
"gitbook-plugin-mathjax": "0.0.3",
|
||||
"gitbook-plugin-livereload": "0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "1.18.2",
|
||||
"grunt": "~0.4.2",
|
||||
"grunt-cli": "0.1.11",
|
||||
"grunt-contrib-less": "~0.5.0",
|
||||
"grunt-contrib-requirejs": "0.4.1"
|
||||
"grunt-contrib-requirejs": "0.4.1",
|
||||
"grunt-bower-install-simple": "0.9.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "export TESTING=true; mocha --reporter list"
|
||||
@@ -39,9 +48,19 @@
|
||||
"book",
|
||||
"gitbook"
|
||||
],
|
||||
"author": "Aaron O'Mullan <aaron.omullan@friendco.de>",
|
||||
"author": "FriendCode <contact@friendco.de>",
|
||||
"license": "Apache 2",
|
||||
"bugs": {
|
||||
"url": "https://github.com/GitbookIO/gitbook/issues"
|
||||
}
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Aaron O'Mullan",
|
||||
"email": "aaron.omullan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Samy Pessé",
|
||||
"email": "samypesse@gmail.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
# Summary
|
||||
|
||||
* [Custom name for Introduction](README.md)
|
||||
* [Chapter 1](chapter-1/README.md)
|
||||
* [Article 1](chapter-1/ARTICLE1.md)
|
||||
* [Article 2](chapter-1/ARTICLE2.md)
|
||||
* [article 1.2.1](chapter-1/ARTICLE-1-2-1.md)
|
||||
* [article 1.2.2](chapter-1/ARTICLE-1-2-2.md)
|
||||
* [Chapter 2](chapter-2/README.md)
|
||||
* [Chapter 3](chapter-3/README.md)
|
||||
* [Chapter 4](chapter-4/README.md)
|
||||
* Unfinished article
|
||||
* Unfinished Chapter
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
# Images Test
|
||||
|
||||
This is a test for images path calculation. It supposed this fiel is in a syntax/ folder
|
||||
|
||||
### #
|
||||
|
||||
[](./preview.png)
|
||||
|
||||
### 2
|
||||
|
||||
[](./preview2.png)
|
||||
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
# Beautiful chapter
|
||||
|
||||
Here is a nice included snippet :
|
||||
|
||||
```c
|
||||
{{ included.c }}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
An exercise using includes
|
||||
|
||||
```c
|
||||
{{ included.c }}
|
||||
|
||||
Remove this extra code at the end
|
||||
```
|
||||
|
||||
```c
|
||||
{{ included.c }}
|
||||
```
|
||||
|
||||
```c
|
||||
{{ included.c }}
|
||||
|
||||
This validation code is wrong but who cares ?
|
||||
```
|
||||
|
||||
----
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
# Nice course
|
||||
|
||||
Check out this other chapter [Test](test.md)
|
||||
|
||||
Check out this other chapter [Test](../before.md)
|
||||
Vendored
+2
@@ -3,6 +3,8 @@
|
||||
* [Chapter 1](chapter-1/README.md)
|
||||
* [Article 1](chapter-1/ARTICLE1.md)
|
||||
* [Article 2](chapter-1/ARTICLE2.md)
|
||||
* [article 1.2.1](chapter-1/ARTICLE-1-2-1.md)
|
||||
* [article 1.2.2](chapter-1/ARTICLE-1-2-2.md)
|
||||
* [Chapter 2](chapter-2/README.md)
|
||||
* [Chapter 3](chapter-3/README.md)
|
||||
* [Chapter 4](chapter-4/README.md)
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
# This is a test
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
# Summary
|
||||
|
||||
* [test](test.md)
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
# Test
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
# This should fail
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("All is well\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
var _ = require('lodash');
|
||||
var Q = require('q');
|
||||
var path = require('path');
|
||||
var tmp = require('tmp');
|
||||
var assert = require('assert');
|
||||
|
||||
var generate = require("../lib/generate");
|
||||
|
||||
var generateTmpBook = function(path) {
|
||||
return ;
|
||||
};
|
||||
|
||||
|
||||
var BOOKS = {
|
||||
"book1": true,
|
||||
"book2": false
|
||||
};
|
||||
|
||||
describe('Site Generation', function () {
|
||||
var ret = {};
|
||||
|
||||
beforeEach(function(done){
|
||||
Q.all(_.map(BOOKS, function(state, bookName) {
|
||||
return Q.nfcall(tmp.dir)
|
||||
.then(function(_dir) {
|
||||
return generate.folder({
|
||||
input: path.join(__dirname, "fixtures", bookName),
|
||||
output: _dir
|
||||
});
|
||||
})
|
||||
.then(function(_book) {
|
||||
ret[bookName] = _book;
|
||||
}, function(err) {
|
||||
// ignore errors here
|
||||
});
|
||||
}))
|
||||
.fin(done);
|
||||
});
|
||||
|
||||
|
||||
it('should generate the valid sites', function() {
|
||||
_.each(BOOKS, function(state, bookName) {
|
||||
assert((ret[bookName] != null) == state);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
|
||||
var page = require('../').parse.page;
|
||||
|
||||
var FIXTURES_DIR = path.join(__dirname, './fixtures/');
|
||||
|
||||
function loadPage (name, options) {
|
||||
var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8');
|
||||
return page(CONTENT, options);
|
||||
}
|
||||
|
||||
|
||||
describe('Code includes', function() {
|
||||
|
||||
var LEXED = loadPage('INCLUDES', {
|
||||
'dir': FIXTURES_DIR,
|
||||
});
|
||||
|
||||
var INCLUDED_C = fs.readFileSync(path.join(FIXTURES_DIR, 'included.c'), 'utf8');
|
||||
|
||||
it('should work for snippets', function() {
|
||||
assert.equal(LEXED[0].type, 'normal');
|
||||
// Has replaced include
|
||||
assert.equal(
|
||||
LEXED[0].content.indexOf('{{ included.c }}'),
|
||||
-1
|
||||
);
|
||||
});
|
||||
|
||||
it('should work for exercises', function() {
|
||||
assert.equal(LEXED[1].type, 'exercise');
|
||||
|
||||
// Solution is trimmed version of source
|
||||
assert.equal(LEXED[1].code.solution, INCLUDED_C.trim());
|
||||
});
|
||||
});
|
||||
+29
-2
@@ -7,7 +7,9 @@ var navigation = require('../').parse.navigation;
|
||||
|
||||
|
||||
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.md'), 'utf8');
|
||||
var ALT_CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/ALTERNATIVE_SUMMARY.md'), 'utf8');
|
||||
var LEXED = summary(CONTENT);
|
||||
var ALT_LEXED = summary(ALT_CONTENT);
|
||||
|
||||
|
||||
describe('Summary navigation', function() {
|
||||
@@ -18,6 +20,8 @@ describe('Summary navigation', function() {
|
||||
'chapter-1/ARTICLE1.md',
|
||||
'chapter-1/ARTICLE2.md',
|
||||
'chapter-2/README.md',
|
||||
'chapter-1/ARTICLE-1-2-1.md',
|
||||
'chapter-1/ARTICLE-1-2-2.md'
|
||||
]);
|
||||
|
||||
// Make sure it found the files we gave it
|
||||
@@ -26,6 +30,8 @@ describe('Summary navigation', function() {
|
||||
assert(nav['chapter-1/ARTICLE1.md']);
|
||||
assert(nav['chapter-1/ARTICLE2.md']);
|
||||
assert(nav['chapter-2/README.md']);
|
||||
assert(nav['chapter-1/ARTICLE-1-2-1.md']);
|
||||
assert(nav['chapter-1/ARTICLE-1-2-2.md']);
|
||||
|
||||
|
||||
assert.equal(nav['README.md'].prev, null);
|
||||
@@ -38,9 +44,15 @@ describe('Summary navigation', function() {
|
||||
assert.equal(nav['chapter-1/ARTICLE1.md'].next.path, 'chapter-1/ARTICLE2.md');
|
||||
|
||||
assert.equal(nav['chapter-1/ARTICLE2.md'].prev.path, 'chapter-1/ARTICLE1.md');
|
||||
assert.equal(nav['chapter-1/ARTICLE2.md'].next.path, 'chapter-2/README.md');
|
||||
assert.equal(nav['chapter-1/ARTICLE2.md'].next.path, 'chapter-1/ARTICLE-1-2-1.md');
|
||||
|
||||
assert.equal(nav['chapter-2/README.md'].prev.path, 'chapter-1/ARTICLE2.md');
|
||||
assert.equal(nav['chapter-1/ARTICLE-1-2-1.md'].prev.path, 'chapter-1/ARTICLE2.md');
|
||||
assert.equal(nav['chapter-1/ARTICLE-1-2-1.md'].next.path, 'chapter-1/ARTICLE-1-2-2.md');
|
||||
|
||||
assert.equal(nav['chapter-1/ARTICLE-1-2-2.md'].prev.path, 'chapter-1/ARTICLE-1-2-1.md');
|
||||
assert.equal(nav['chapter-1/ARTICLE-1-2-2.md'].next.path, 'chapter-2/README.md');
|
||||
|
||||
assert.equal(nav['chapter-2/README.md'].prev.path, 'chapter-1/ARTICLE-1-2-2.md');
|
||||
assert.equal(nav['chapter-2/README.md'].next.path, 'chapter-3/README.md');
|
||||
});
|
||||
|
||||
@@ -66,6 +78,21 @@ describe('Summary navigation', function() {
|
||||
assert.equal(nav['chapter-3/README.md'].level, '3');
|
||||
});
|
||||
|
||||
it('should have a default README node', function() {
|
||||
var nav = navigation(LEXED);
|
||||
|
||||
assert.equal(nav['README.md'].level, '0');
|
||||
assert.equal(nav['README.md'].title, 'Introduction');
|
||||
});
|
||||
|
||||
it('Should allow README node to be customized', function() {
|
||||
var nav = navigation(ALT_LEXED);
|
||||
|
||||
assert(nav['README.md']);
|
||||
assert.equal(nav['README.md'].level, '0');
|
||||
assert.notEqual(nav['README.md'].title, 'Introduction');
|
||||
});
|
||||
|
||||
it('should not accept null paths', function() {
|
||||
var nav = navigation(LEXED);
|
||||
|
||||
|
||||
+61
-5
@@ -36,10 +36,6 @@ describe('Page parsing', function() {
|
||||
assert(LEXED[2].content);
|
||||
});
|
||||
|
||||
it('should make image URLs relative', function() {
|
||||
assert(LEXED[2].content.indexOf('_book/assets/my-pretty-picture.png') !== -1);
|
||||
});
|
||||
|
||||
it('should gen code and content for exercise sections', function() {
|
||||
assert(LEXED[1].content);
|
||||
assert(LEXED[1].code);
|
||||
@@ -88,9 +84,69 @@ describe('Relative links', function() {
|
||||
repo: 'GitBookIO/javascript',
|
||||
|
||||
// Imaginary folder of markdown file
|
||||
dir: 'course'
|
||||
dir: 'course',
|
||||
outdir: './'
|
||||
});
|
||||
|
||||
assert(LEXED[0].content.indexOf('https://github.com/GitBookIO/javascript/blob/src/something.cpp') !== -1);
|
||||
});
|
||||
|
||||
it('should replace link to .md by link to .html', function() {
|
||||
var LEXED = loadPage('MARKDOWN_LINKS', {
|
||||
// GitHub repo ID
|
||||
repo: 'GitBookIO/javascript',
|
||||
|
||||
// Imaginary folder of markdown file
|
||||
dir: 'course',
|
||||
outdir: 'course'
|
||||
});
|
||||
|
||||
assert(LEXED[0].content.indexOf('test.html') !== -1);
|
||||
assert(LEXED[0].content.indexOf('../before.html') !== -1);
|
||||
});
|
||||
|
||||
it('should replace link to .md by link to page in format single page', function() {
|
||||
var LEXED = loadPage('MARKDOWN_LINKS', {
|
||||
// GitHub repo ID
|
||||
repo: 'GitBookIO/javascript',
|
||||
|
||||
// Imaginary folder of markdown file
|
||||
dir: 'course',
|
||||
outdir: './',
|
||||
singleFile: true
|
||||
});
|
||||
|
||||
assert(LEXED[0].content.indexOf('#course/test.md') !== -1);
|
||||
assert(LEXED[0].content.indexOf('#before.md') !== -1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Relative images', function() {
|
||||
it('should keep image relative with considering output directory in site format', function() {
|
||||
var LEXED = loadPage('IMAGES', {
|
||||
// GitHub repo ID
|
||||
repo: 'GitBookIO/javascript',
|
||||
|
||||
// Imaginary folder of markdown file
|
||||
dir: 'syntax',
|
||||
outdir: 'syntax'
|
||||
});
|
||||
|
||||
assert(LEXED[0].content.indexOf('"preview.png"') !== -1);
|
||||
assert(LEXED[0].content.indexOf('"../preview2.png"') !== -1);
|
||||
});
|
||||
|
||||
it('should keep image relative with considering output directory in page format', function() {
|
||||
var LEXED = loadPage('IMAGES', {
|
||||
// GitHub repo ID
|
||||
repo: 'GitBookIO/javascript',
|
||||
|
||||
// Imaginary folder of markdown file
|
||||
dir: 'syntax',
|
||||
outdir: './'
|
||||
});
|
||||
|
||||
assert(LEXED[0].content.indexOf('"syntax/preview.png"') !== -1);
|
||||
assert(LEXED[0].content.indexOf('"preview2.png"') !== -1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
|
||||
var Plugin = require('../').generate.Plugin;
|
||||
|
||||
describe('Plugin validation', function () {
|
||||
var plugin = new Plugin("plugin", __dirname);
|
||||
|
||||
it('should be valid', function() {
|
||||
assert(plugin.isValid());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Plugin list of names', function () {
|
||||
var firstDefault = _.first(Plugin.defaults);
|
||||
|
||||
it('should convert string to array', function() {
|
||||
var _name = "test";
|
||||
assert(_.contains(Plugin.normalizeNames(_name), _name));
|
||||
});
|
||||
|
||||
it('should contains default plugins', function() {
|
||||
assert(_.contains(Plugin.normalizeNames([]), firstDefault));
|
||||
});
|
||||
|
||||
it('should remove name starting with -', function() {
|
||||
assert(!_.contains(Plugin.normalizeNames(["-"+firstDefault]), firstDefault));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Plugin defaults loading', function () {
|
||||
var ret = true;
|
||||
|
||||
beforeEach(function(done){
|
||||
Plugin.fromList(Plugin.defaults, __dirname)
|
||||
.then(function(_r) {
|
||||
ret = _r;
|
||||
}, function(err) {
|
||||
ret = null;
|
||||
})
|
||||
.fin(done);
|
||||
});
|
||||
|
||||
|
||||
it('should load defaults addons', function() {
|
||||
assert(ret != null);
|
||||
});
|
||||
});
|
||||
+17
-12
@@ -12,13 +12,13 @@ var LEXED = summary(CONTENT);
|
||||
describe('Summary parsing', function () {
|
||||
|
||||
it('should detect chapters', function() {
|
||||
assert.equal(LEXED.chapters.length, 5);
|
||||
assert.equal(LEXED.chapters.length, 6);
|
||||
});
|
||||
|
||||
it('should support articles', function() {
|
||||
assert.equal(LEXED.chapters[0].articles.length, 2);
|
||||
assert.equal(LEXED.chapters[1].articles.length, 0);
|
||||
assert.equal(LEXED.chapters[1].articles.length, 2);
|
||||
assert.equal(LEXED.chapters[2].articles.length, 0);
|
||||
assert.equal(LEXED.chapters[3].articles.length, 0);
|
||||
});
|
||||
|
||||
it('should detect paths and titles', function() {
|
||||
@@ -26,29 +26,34 @@ describe('Summary parsing', function () {
|
||||
assert(LEXED.chapters[1].path);
|
||||
assert(LEXED.chapters[2].path);
|
||||
assert(LEXED.chapters[3].path);
|
||||
assert.equal(LEXED.chapters[4].path, null);
|
||||
assert(LEXED.chapters[4].path);
|
||||
assert.equal(LEXED.chapters[5].path, null);
|
||||
|
||||
assert(LEXED.chapters[0].title);
|
||||
assert(LEXED.chapters[1].title);
|
||||
assert(LEXED.chapters[2].title);
|
||||
assert(LEXED.chapters[3].title);
|
||||
assert(LEXED.chapters[4].title);
|
||||
assert(LEXED.chapters[5].title);
|
||||
});
|
||||
|
||||
it('should normalize paths from .md to .html', function() {
|
||||
assert.equal(LEXED.chapters[0].path,'chapter-1/README.md');
|
||||
assert.equal(LEXED.chapters[1].path,'chapter-2/README.md');
|
||||
assert.equal(LEXED.chapters[2].path,'chapter-3/README.md');
|
||||
assert.equal(LEXED.chapters[0].path,'README.md');
|
||||
assert.equal(LEXED.chapters[1].path,'chapter-1/README.md');
|
||||
assert.equal(LEXED.chapters[2].path,'chapter-2/README.md');
|
||||
assert.equal(LEXED.chapters[3].path,'chapter-3/README.md');
|
||||
});
|
||||
|
||||
it('should detect levels correctly', function() {
|
||||
var c = LEXED.chapters;
|
||||
|
||||
assert.equal(c[0].level, '1');
|
||||
assert.equal(c[1].level, '2');
|
||||
assert.equal(c[2].level, '3');
|
||||
assert.equal(c[0].level, '0');
|
||||
assert.equal(c[1].level, '1');
|
||||
assert.equal(c[2].level, '2');
|
||||
assert.equal(c[3].level, '3');
|
||||
|
||||
assert.equal(c[0].articles[0].level, '1.1');
|
||||
assert.equal(c[0].articles[1].level, '1.2');
|
||||
assert.equal(c[1].articles[0].level, '1.1');
|
||||
assert.equal(c[1].articles[1].level, '1.2');
|
||||
assert.equal(c[1].articles[1].articles[0].level, '1.2.1');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# GitBook Theme
|
||||
|
||||
For creating a theme for GitBook, just copy this folder. The theme folder should at least contains two folders: `assets` and `templates`.
|
||||
|
||||
The theme can be changed using the option ```--theme=<path>```
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,7 @@
|
||||
define([
|
||||
"jQuery"
|
||||
], function($) {
|
||||
var events = $({});
|
||||
|
||||
return events;
|
||||
});
|
||||
@@ -1,9 +1,13 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"ace/ace",
|
||||
"ace/theme-tomorrow",
|
||||
"ace/mode-javascript",
|
||||
"utils/execute",
|
||||
"utils/analytic",
|
||||
"core/events",
|
||||
"core/state"
|
||||
], function($, execute, analytic, state){
|
||||
], function($, _ace, _aceTheme, _aceMode, execute, events, state){
|
||||
|
||||
// Bind an exercise
|
||||
var prepareExercise = function($exercise) {
|
||||
var codeSolution = $exercise.find(".code-solution").text();
|
||||
@@ -19,7 +23,7 @@ define([
|
||||
$exercise.find(".action-submit").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
analytic.track("exercise.submit", {type: "code"});
|
||||
events.trigger("exercise.submit", {type: "code"});
|
||||
|
||||
execute("javascript", editor.getValue(), codeValidation, codeContext, function(err, result) {
|
||||
$exercise.toggleClass("return-error", err != null);
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/storage"
|
||||
], function($, storage) {
|
||||
var fontState;
|
||||
|
||||
var THEMES = {
|
||||
"white": 0,
|
||||
"sepia": 1,
|
||||
"night": 2
|
||||
};
|
||||
|
||||
var FAMILY = {
|
||||
"serif": 0,
|
||||
"sans": 1
|
||||
};
|
||||
|
||||
var togglePopover = function(e) {
|
||||
var $dropdown = $("#font-settings-wrapper .dropdown-menu");
|
||||
|
||||
$dropdown.toggleClass("open");
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
var closePopover = function(e) {
|
||||
var $dropdown = $("#font-settings-wrapper .dropdown-menu");
|
||||
|
||||
$dropdown.removeClass("open");
|
||||
};
|
||||
|
||||
var enlargeFontSize = function(e){
|
||||
if (fontState.size < 4){
|
||||
fontState.size++;
|
||||
fontState.save();
|
||||
}
|
||||
};
|
||||
|
||||
var reduceFontSize = function(e){
|
||||
if (fontState.size > 0){
|
||||
fontState.size--;
|
||||
fontState.save();
|
||||
}
|
||||
};
|
||||
|
||||
var changeFontFamily = function(){
|
||||
var index = $(this).data("font");
|
||||
|
||||
fontState.family = index;
|
||||
fontState.save();
|
||||
};
|
||||
|
||||
var changeColorTheme = function(){
|
||||
var $book = $(".book");
|
||||
var index = $(this).data("theme");
|
||||
|
||||
if (fontState.theme !== 0)
|
||||
$book.removeClass("color-theme-"+fontState.theme);
|
||||
|
||||
fontState.theme = index;
|
||||
if (fontState.theme !== 0)
|
||||
$book.addClass("color-theme-"+fontState.theme);
|
||||
|
||||
fontState.save();
|
||||
};
|
||||
|
||||
var update = function() {
|
||||
var $book = $(".book");
|
||||
|
||||
$(".font-settings .font-family-list li").removeClass("active");
|
||||
$(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
|
||||
|
||||
$book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
|
||||
$book.addClass("font-size-"+fontState.size);
|
||||
$book.addClass("font-family-"+fontState.family);
|
||||
|
||||
if(fontState.theme !== 0) {
|
||||
$book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
|
||||
$book.addClass("color-theme-"+fontState.theme);
|
||||
}
|
||||
};
|
||||
|
||||
var init = function(config) {
|
||||
var $toggle, $bookBody, $dropdown, $book;
|
||||
|
||||
//Find DOM elements.
|
||||
$book = $(".book");
|
||||
$toggle = $(".book-header .toggle-font-settings");
|
||||
$dropdown = $("#font-settings-wrapper .dropdown-menu");
|
||||
$bookBody = $(".book-body");
|
||||
|
||||
// Instantiate font state object
|
||||
fontState = storage.get("fontState", {
|
||||
size: config.size || 2,
|
||||
family: FAMILY[config.family || "sans"],
|
||||
theme: THEMES[config.theme || "white"]
|
||||
});
|
||||
fontState.save = function(){
|
||||
storage.set("fontState",fontState);
|
||||
update();
|
||||
};
|
||||
|
||||
update();
|
||||
|
||||
//Add event listeners
|
||||
$(document).on('click', "#enlarge-font-size", enlargeFontSize);
|
||||
$(document).on('click', "#reduce-font-size", reduceFontSize);
|
||||
|
||||
$(document).on('click', "#font-settings-wrapper .font-family-list li", changeFontFamily);
|
||||
$(document).on('click', "#font-settings-wrapper .color-theme-list button", changeColorTheme);
|
||||
|
||||
$(document).on('click', ".book-header .toggle-font-settings", togglePopover);
|
||||
$(document).on('click', "#font-settings-wrapper .dropdown-menu", function(e){ e.stopPropagation(); });
|
||||
$(document).on("click", closePopover);
|
||||
};
|
||||
|
||||
return {
|
||||
init: init,
|
||||
update: update
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
define([
|
||||
"jQuery"
|
||||
], function($) {
|
||||
var showLoading = function(p) {
|
||||
$(".book").addClass("is-loading");
|
||||
p.always(function() {
|
||||
$(".book").removeClass("is-loading");
|
||||
});
|
||||
|
||||
return p;
|
||||
};
|
||||
|
||||
return {
|
||||
show: showLoading
|
||||
};
|
||||
});
|
||||
@@ -1,34 +1,41 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/analytic",
|
||||
"utils/url",
|
||||
"core/events",
|
||||
"core/state",
|
||||
"core/search",
|
||||
"core/progress",
|
||||
"core/exercise",
|
||||
"core/quiz"
|
||||
], function($, analytic, state, search, progress, exercises, quiz) {
|
||||
"core/quiz",
|
||||
"core/loading"
|
||||
], function($, URL, events, state, progress, exercises, quiz, loading) {
|
||||
var prev, next;
|
||||
var githubCountStars, githubCountWatch;
|
||||
|
||||
var updateHistory = function(url, title) {
|
||||
history.pushState({ path: url }, title, url);
|
||||
};
|
||||
var usePushState = (typeof history.pushState !== "undefined");
|
||||
|
||||
var handleNavigation = function(url, push) {
|
||||
if (typeof history.pushState === "undefined") {
|
||||
var handleNavigation = function(relativeUrl, push) {
|
||||
var url = URL.join(window.location.pathname, relativeUrl);
|
||||
console.log("navigate to ", url, "baseurl="+relativeUrl, "current="+window.location.pathname);
|
||||
|
||||
if (!usePushState) {
|
||||
// Refresh the page to the new URL if pushState not supported
|
||||
location.href = url;
|
||||
location.href = relativeUrl;
|
||||
return
|
||||
}
|
||||
|
||||
return $.get(url)
|
||||
return loading.show($.get(url)
|
||||
.done(function (html) {
|
||||
// Push url to history
|
||||
if (push) history.pushState({ path: url }, null, url);
|
||||
|
||||
// Replace html content
|
||||
html = html.replace( /<(\/?)(html|head|body)([^>]*)>/ig, function(a,b,c,d){
|
||||
return '<' + b + 'div' + ( b ? '' : ' data-element="' + c + '"' ) + d + '>';
|
||||
});
|
||||
|
||||
var $page = $(html);
|
||||
var $pageHead = $page.find("[data-element=head]");
|
||||
var $pageBody = $page.find('.book');
|
||||
|
||||
// Merge heads
|
||||
var headContent = $pageHead.html()
|
||||
@@ -38,24 +45,22 @@ define([
|
||||
});
|
||||
$("head").html(headContent);
|
||||
|
||||
// Update header, body
|
||||
$('.book-header').html($page.find('.book-header').html());
|
||||
$('.book-body').html($page.find('.book-body').html());
|
||||
|
||||
// Update summary
|
||||
// Merge body
|
||||
var bodyClass = $(".book").attr("class");
|
||||
var scrollPosition = $('.book-summary .summary').scrollTop();
|
||||
$('.book-summary').html($page.find('.book-summary').html());
|
||||
$pageBody.toggleClass("with-summary", $(".book").hasClass("with-summary"))
|
||||
|
||||
$(".book").replaceWith($pageBody);
|
||||
$(".book").attr("class", bodyClass);
|
||||
$('.book-summary .summary').scrollTop(scrollPosition);
|
||||
|
||||
// Update state
|
||||
state.update($("html"));
|
||||
|
||||
if (push) updateHistory(url, null);
|
||||
preparePage();
|
||||
})
|
||||
.fail(function () {
|
||||
location.href = url;
|
||||
});
|
||||
.fail(function (e) {
|
||||
location.href = relativeUrl;
|
||||
}));
|
||||
};
|
||||
|
||||
var updateGitHubCounts = function() {
|
||||
@@ -90,9 +95,6 @@ define([
|
||||
// Focus on content
|
||||
$pageWrapper.focus();
|
||||
|
||||
// Prepare search bar
|
||||
search.prepare();
|
||||
|
||||
// Update GitHub count
|
||||
if (state.githubId) {
|
||||
if (githubCountStars) {
|
||||
@@ -108,7 +110,7 @@ define([
|
||||
}
|
||||
|
||||
// Send to mixpanel
|
||||
analytic.track("page.view");
|
||||
events.trigger("page.change");
|
||||
};
|
||||
|
||||
var handlePagination = function (e) {
|
||||
@@ -129,7 +131,7 @@ define([
|
||||
if (url) handleNavigation(url, true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
var init = function() {
|
||||
// Prevent cache so that using the back button works
|
||||
@@ -146,14 +148,13 @@ define([
|
||||
if (event.state === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return handleNavigation(event.state.path, false);
|
||||
};
|
||||
|
||||
$(document).on('click', ".navigation-prev", handlePagination);
|
||||
$(document).on('click', ".navigation-next", handlePagination);
|
||||
$(document).on('click', ".summary [data-path] a", handlePagination);
|
||||
|
||||
|
||||
$(window).resize(updateNavigationPosition);
|
||||
|
||||
// Prepare current page
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/execute",
|
||||
"utils/analytic",
|
||||
"core/events",
|
||||
"core/state"
|
||||
], function($, execute, analytic, state){
|
||||
], function($, execute, events, state){
|
||||
// Bind an exercise
|
||||
var prepareQuiz = function($quiz) {
|
||||
|
||||
@@ -14,14 +14,17 @@ define([
|
||||
// Submit: test code
|
||||
$quiz.find(".action-submit").click(function(e) {
|
||||
e.preventDefault();
|
||||
analytic.track("exercise.submit", {type: "quiz"});
|
||||
events.trigger("exercise.submit", {type: "quiz"});
|
||||
$quiz.find("tr.alert-danger,li.alert-danger").removeClass("alert-danger");
|
||||
$quiz.find(".alert-success,.alert-danger").addClass("hidden");
|
||||
|
||||
$quiz.find(".question").each(function(q) {
|
||||
var result = true;
|
||||
var $answers = $quiz.find(".question-answers").slice(q).find("input[type=radio], input[type=checkbox]");
|
||||
$(this).find("input[type=radio],input[type=checkbox]").each(function(i) {
|
||||
|
||||
var $questions = $(this).find(".question-content").find("input[type=radio], input[type=checkbox]");
|
||||
var $answers = $(this).find(".question-answers").find("input[type=radio], input[type=checkbox]");
|
||||
|
||||
$questions.each(function(i) {
|
||||
var correct = $(this).is(":checked") === $answers.slice(i).first().is(":checked");
|
||||
result = result && correct;
|
||||
if (!correct) {
|
||||
|
||||
@@ -67,12 +67,10 @@ define([
|
||||
e.preventDefault();
|
||||
toggleSearch();
|
||||
});
|
||||
};
|
||||
|
||||
var prepare = function() {
|
||||
var $searchInput = $(".book-search input");
|
||||
|
||||
$searchInput.keyup(function(e) {
|
||||
// Type in search bar
|
||||
$(document).on("keyup", ".book-search input", function(e) {
|
||||
var key = (e.keyCode ? e.keyCode : e.which);
|
||||
var q = $(this).val();
|
||||
|
||||
@@ -89,13 +87,12 @@ define([
|
||||
_.pluck(results, "path")
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
return {
|
||||
init: init,
|
||||
search: search,
|
||||
toggle: toggleSearch,
|
||||
prepare: prepare
|
||||
toggle: toggleSearch
|
||||
};
|
||||
});
|
||||
@@ -1,11 +1,10 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"lodash",
|
||||
"utils/storage",
|
||||
"utils/platform",
|
||||
"core/state"
|
||||
], function(_, storage, platform, state) {
|
||||
var $summary = state.$book.find(".book-summary");
|
||||
|
||||
], function($, _, storage, platform, state) {
|
||||
// Toggle sidebar with or withour animation
|
||||
var toggleSidebar = function(_state, animation) {
|
||||
if (state != null && isOpen() == _state) return;
|
||||
@@ -38,6 +37,8 @@ define([
|
||||
|
||||
// Filter summary with a list of path
|
||||
var filterSummary = function(paths) {
|
||||
var $summary = $(".book-summary");
|
||||
|
||||
$summary.find("li").each(function() {
|
||||
var path = $(this).data("path");
|
||||
var st = paths == null || _.contains(paths, path);
|
||||
@@ -48,7 +49,6 @@ define([
|
||||
};
|
||||
|
||||
return {
|
||||
$el: $summary,
|
||||
init: init,
|
||||
toggle: toggleSidebar,
|
||||
filter: filterSummary
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
require([
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/storage",
|
||||
"utils/analytic",
|
||||
"utils/sharing",
|
||||
"utils/appcache",
|
||||
|
||||
"core/events",
|
||||
"core/font-settings",
|
||||
"core/state",
|
||||
"core/keyboard",
|
||||
"core/navigation",
|
||||
"core/progress",
|
||||
"core/sidebar",
|
||||
"core/search"
|
||||
], function($, storage, analytic, sharing, state, keyboard, navigation, progress, sidebar, search){
|
||||
$(document).ready(function() {
|
||||
], function($, storage, appCache, sharing, events, fontSettings, state, keyboard, navigation, progress, sidebar, search){
|
||||
var start = function(config) {
|
||||
var $book;
|
||||
$book = state.$book;
|
||||
|
||||
@@ -29,10 +31,23 @@ require([
|
||||
// Init keyboard
|
||||
keyboard.init();
|
||||
|
||||
// Init appcache
|
||||
appCache.init();
|
||||
|
||||
// Bind sharing button
|
||||
sharing.init();
|
||||
|
||||
|
||||
// Init navigation
|
||||
navigation.init();
|
||||
});
|
||||
|
||||
//Init font settings
|
||||
fontSettings.init(config.fontSettings || {});
|
||||
|
||||
events.trigger("start", config);
|
||||
}
|
||||
|
||||
return {
|
||||
start: start,
|
||||
events: events
|
||||
};
|
||||
});
|
||||
@@ -1,33 +0,0 @@
|
||||
define([
|
||||
"lodash",
|
||||
"mixpanel"
|
||||
], function(_, mixpanel) {
|
||||
mixpanel.init("01eb2b950ae09a5fdb15a98dcc5ff20e", {
|
||||
loaded: function() {
|
||||
track("page.start");
|
||||
}
|
||||
});
|
||||
|
||||
var isAvailable = function() {
|
||||
return (
|
||||
typeof mixpanel !== "undefined" &&
|
||||
typeof mixpanel.track === "function"
|
||||
);
|
||||
};
|
||||
|
||||
var track = function(e, data) {
|
||||
if (!isAvailable()) {
|
||||
console.warn("tracking not available!");
|
||||
return;
|
||||
}
|
||||
console.log("track", e);
|
||||
mixpanel.track(e, _.extend(data || {}, {
|
||||
'domain': window.location.host
|
||||
}));
|
||||
};
|
||||
|
||||
return {
|
||||
isAvailable: isAvailable,
|
||||
track: track
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
define([], function() {
|
||||
var isAvailable = (typeof applicationCache !== "undefined");
|
||||
|
||||
var init = function() {
|
||||
if (!isAvailable) return;
|
||||
|
||||
window.applicationCache.addEventListener('updateready', function() {
|
||||
window.location.reload();
|
||||
}, false);
|
||||
};
|
||||
|
||||
return {
|
||||
init: init
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
define([
|
||||
"vendors/URIjs/src/URI"
|
||||
], function(URI) {
|
||||
// Joins path segments. Preserves initial "/" and resolves ".." and "."
|
||||
// Does not support using ".." to go above/outside the root.
|
||||
// This means that join("foo", "../../bar") will not resolve to "../bar"
|
||||
function join(baseUrl, url) {
|
||||
var theUrl = new URI(url);
|
||||
if (theUrl.is("relative")) {
|
||||
theUrl = theUrl.absoluteTo(baseUrl);
|
||||
}
|
||||
return theUrl.toString();
|
||||
}
|
||||
|
||||
// A simple function to get the dirname of a path
|
||||
// Trailing slashes are ignored. Leading slash is preserved.
|
||||
function dirname(path) {
|
||||
return join(path, "..");
|
||||
}
|
||||
|
||||
// test if a path or url is absolute
|
||||
function isAbsolute(path) {
|
||||
if (!path) return false;
|
||||
|
||||
return (path[0] == "/" || path.indexOf("http://") == 0 || path.indexOf("https://") == 0);
|
||||
}
|
||||
|
||||
return {
|
||||
dirname: dirname,
|
||||
join: join,
|
||||
isAbsolute: isAbsolute
|
||||
};
|
||||
})
|
||||
Vendored
-9111
File diff suppressed because it is too large
Load Diff
Vendored
-6785
File diff suppressed because it is too large
Load Diff
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");
|
||||
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
||||
-953
@@ -1,953 +0,0 @@
|
||||
/*global define:false */
|
||||
/**
|
||||
* Copyright 2013 Craig Campbell
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Mousetrap is a simple keyboard shortcut library for Javascript with
|
||||
* no external dependencies
|
||||
*
|
||||
* @version 1.4.6
|
||||
* @url craig.is/killing/mice
|
||||
*/
|
||||
(function(window, document, undefined) {
|
||||
|
||||
/**
|
||||
* mapping of special keycodes to their corresponding keys
|
||||
*
|
||||
* everything in this dictionary cannot use keypress events
|
||||
* so it has to be here to map to the correct keycodes for
|
||||
* keyup/keydown events
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var _MAP = {
|
||||
8: 'backspace',
|
||||
9: 'tab',
|
||||
13: 'enter',
|
||||
16: 'shift',
|
||||
17: 'ctrl',
|
||||
18: 'alt',
|
||||
20: 'capslock',
|
||||
27: 'esc',
|
||||
32: 'space',
|
||||
33: 'pageup',
|
||||
34: 'pagedown',
|
||||
35: 'end',
|
||||
36: 'home',
|
||||
37: 'left',
|
||||
38: 'up',
|
||||
39: 'right',
|
||||
40: 'down',
|
||||
45: 'ins',
|
||||
46: 'del',
|
||||
91: 'meta',
|
||||
93: 'meta',
|
||||
224: 'meta'
|
||||
},
|
||||
|
||||
/**
|
||||
* mapping for special characters so they can support
|
||||
*
|
||||
* this dictionary is only used incase you want to bind a
|
||||
* keyup or keydown event to one of these keys
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
_KEYCODE_MAP = {
|
||||
106: '*',
|
||||
107: '+',
|
||||
109: '-',
|
||||
110: '.',
|
||||
111 : '/',
|
||||
186: ';',
|
||||
187: '=',
|
||||
188: ',',
|
||||
189: '-',
|
||||
190: '.',
|
||||
191: '/',
|
||||
192: '`',
|
||||
219: '[',
|
||||
220: '\\',
|
||||
221: ']',
|
||||
222: '\''
|
||||
},
|
||||
|
||||
/**
|
||||
* this is a mapping of keys that require shift on a US keypad
|
||||
* back to the non shift equivelents
|
||||
*
|
||||
* this is so you can use keyup events with these keys
|
||||
*
|
||||
* note that this will only work reliably on US keyboards
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
_SHIFT_MAP = {
|
||||
'~': '`',
|
||||
'!': '1',
|
||||
'@': '2',
|
||||
'#': '3',
|
||||
'$': '4',
|
||||
'%': '5',
|
||||
'^': '6',
|
||||
'&': '7',
|
||||
'*': '8',
|
||||
'(': '9',
|
||||
')': '0',
|
||||
'_': '-',
|
||||
'+': '=',
|
||||
':': ';',
|
||||
'\"': '\'',
|
||||
'<': ',',
|
||||
'>': '.',
|
||||
'?': '/',
|
||||
'|': '\\'
|
||||
},
|
||||
|
||||
/**
|
||||
* this is a list of special strings you can use to map
|
||||
* to modifier keys when you specify your keyboard shortcuts
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
_SPECIAL_ALIASES = {
|
||||
'option': 'alt',
|
||||
'command': 'meta',
|
||||
'return': 'enter',
|
||||
'escape': 'esc',
|
||||
'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl'
|
||||
},
|
||||
|
||||
/**
|
||||
* variable to store the flipped version of _MAP from above
|
||||
* needed to check if we should use keypress or not when no action
|
||||
* is specified
|
||||
*
|
||||
* @type {Object|undefined}
|
||||
*/
|
||||
_REVERSE_MAP,
|
||||
|
||||
/**
|
||||
* a list of all the callbacks setup via Mousetrap.bind()
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
_callbacks = {},
|
||||
|
||||
/**
|
||||
* direct map of string combinations to callbacks used for trigger()
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
_directMap = {},
|
||||
|
||||
/**
|
||||
* keeps track of what level each sequence is at since multiple
|
||||
* sequences can start out with the same sequence
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
_sequenceLevels = {},
|
||||
|
||||
/**
|
||||
* variable to store the setTimeout call
|
||||
*
|
||||
* @type {null|number}
|
||||
*/
|
||||
_resetTimer,
|
||||
|
||||
/**
|
||||
* temporary state where we will ignore the next keyup
|
||||
*
|
||||
* @type {boolean|string}
|
||||
*/
|
||||
_ignoreNextKeyup = false,
|
||||
|
||||
/**
|
||||
* temporary state where we will ignore the next keypress
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
_ignoreNextKeypress = false,
|
||||
|
||||
/**
|
||||
* are we currently inside of a sequence?
|
||||
* type of action ("keyup" or "keydown" or "keypress") or false
|
||||
*
|
||||
* @type {boolean|string}
|
||||
*/
|
||||
_nextExpectedAction = false;
|
||||
|
||||
/**
|
||||
* loop through the f keys, f1 to f19 and add them to the map
|
||||
* programatically
|
||||
*/
|
||||
for (var i = 1; i < 20; ++i) {
|
||||
_MAP[111 + i] = 'f' + i;
|
||||
}
|
||||
|
||||
/**
|
||||
* loop through to map numbers on the numeric keypad
|
||||
*/
|
||||
for (i = 0; i <= 9; ++i) {
|
||||
_MAP[i + 96] = i;
|
||||
}
|
||||
|
||||
/**
|
||||
* cross browser add event method
|
||||
*
|
||||
* @param {Element|HTMLDocument} object
|
||||
* @param {string} type
|
||||
* @param {Function} callback
|
||||
* @returns void
|
||||
*/
|
||||
function _addEvent(object, type, callback) {
|
||||
if (object.addEventListener) {
|
||||
object.addEventListener(type, callback, false);
|
||||
return;
|
||||
}
|
||||
|
||||
object.attachEvent('on' + type, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* takes the event and returns the key character
|
||||
*
|
||||
* @param {Event} e
|
||||
* @return {string}
|
||||
*/
|
||||
function _characterFromEvent(e) {
|
||||
|
||||
// for keypress events we should return the character as is
|
||||
if (e.type == 'keypress') {
|
||||
var character = String.fromCharCode(e.which);
|
||||
|
||||
// if the shift key is not pressed then it is safe to assume
|
||||
// that we want the character to be lowercase. this means if
|
||||
// you accidentally have caps lock on then your key bindings
|
||||
// will continue to work
|
||||
//
|
||||
// the only side effect that might not be desired is if you
|
||||
// bind something like 'A' cause you want to trigger an
|
||||
// event when capital A is pressed caps lock will no longer
|
||||
// trigger the event. shift+a will though.
|
||||
if (!e.shiftKey) {
|
||||
character = character.toLowerCase();
|
||||
}
|
||||
|
||||
return character;
|
||||
}
|
||||
|
||||
// for non keypress events the special maps are needed
|
||||
if (_MAP[e.which]) {
|
||||
return _MAP[e.which];
|
||||
}
|
||||
|
||||
if (_KEYCODE_MAP[e.which]) {
|
||||
return _KEYCODE_MAP[e.which];
|
||||
}
|
||||
|
||||
// if it is not in the special map
|
||||
|
||||
// with keydown and keyup events the character seems to always
|
||||
// come in as an uppercase character whether you are pressing shift
|
||||
// or not. we should make sure it is always lowercase for comparisons
|
||||
return String.fromCharCode(e.which).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if two arrays are equal
|
||||
*
|
||||
* @param {Array} modifiers1
|
||||
* @param {Array} modifiers2
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function _modifiersMatch(modifiers1, modifiers2) {
|
||||
return modifiers1.sort().join(',') === modifiers2.sort().join(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* resets all sequence counters except for the ones passed in
|
||||
*
|
||||
* @param {Object} doNotReset
|
||||
* @returns void
|
||||
*/
|
||||
function _resetSequences(doNotReset) {
|
||||
doNotReset = doNotReset || {};
|
||||
|
||||
var activeSequences = false,
|
||||
key;
|
||||
|
||||
for (key in _sequenceLevels) {
|
||||
if (doNotReset[key]) {
|
||||
activeSequences = true;
|
||||
continue;
|
||||
}
|
||||
_sequenceLevels[key] = 0;
|
||||
}
|
||||
|
||||
if (!activeSequences) {
|
||||
_nextExpectedAction = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* finds all callbacks that match based on the keycode, modifiers,
|
||||
* and action
|
||||
*
|
||||
* @param {string} character
|
||||
* @param {Array} modifiers
|
||||
* @param {Event|Object} e
|
||||
* @param {string=} sequenceName - name of the sequence we are looking for
|
||||
* @param {string=} combination
|
||||
* @param {number=} level
|
||||
* @returns {Array}
|
||||
*/
|
||||
function _getMatches(character, modifiers, e, sequenceName, combination, level) {
|
||||
var i,
|
||||
callback,
|
||||
matches = [],
|
||||
action = e.type;
|
||||
|
||||
// if there are no events related to this keycode
|
||||
if (!_callbacks[character]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// if a modifier key is coming up on its own we should allow it
|
||||
if (action == 'keyup' && _isModifier(character)) {
|
||||
modifiers = [character];
|
||||
}
|
||||
|
||||
// loop through all callbacks for the key that was pressed
|
||||
// and see if any of them match
|
||||
for (i = 0; i < _callbacks[character].length; ++i) {
|
||||
callback = _callbacks[character][i];
|
||||
|
||||
// if a sequence name is not specified, but this is a sequence at
|
||||
// the wrong level then move onto the next match
|
||||
if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if the action we are looking for doesn't match the action we got
|
||||
// then we should keep going
|
||||
if (action != callback.action) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if this is a keypress event and the meta key and control key
|
||||
// are not pressed that means that we need to only look at the
|
||||
// character, otherwise check the modifiers as well
|
||||
//
|
||||
// chrome will not fire a keypress if meta or control is down
|
||||
// safari will fire a keypress if meta or meta+shift is down
|
||||
// firefox will fire a keypress if meta or control is down
|
||||
if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) {
|
||||
|
||||
// when you bind a combination or sequence a second time it
|
||||
// should overwrite the first one. if a sequenceName or
|
||||
// combination is specified in this call it does just that
|
||||
//
|
||||
// @todo make deleting its own method?
|
||||
var deleteCombo = !sequenceName && callback.combo == combination;
|
||||
var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level;
|
||||
if (deleteCombo || deleteSequence) {
|
||||
_callbacks[character].splice(i, 1);
|
||||
}
|
||||
|
||||
matches.push(callback);
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* takes a key event and figures out what the modifiers are
|
||||
*
|
||||
* @param {Event} e
|
||||
* @returns {Array}
|
||||
*/
|
||||
function _eventModifiers(e) {
|
||||
var modifiers = [];
|
||||
|
||||
if (e.shiftKey) {
|
||||
modifiers.push('shift');
|
||||
}
|
||||
|
||||
if (e.altKey) {
|
||||
modifiers.push('alt');
|
||||
}
|
||||
|
||||
if (e.ctrlKey) {
|
||||
modifiers.push('ctrl');
|
||||
}
|
||||
|
||||
if (e.metaKey) {
|
||||
modifiers.push('meta');
|
||||
}
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* prevents default for this event
|
||||
*
|
||||
* @param {Event} e
|
||||
* @returns void
|
||||
*/
|
||||
function _preventDefault(e) {
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
e.returnValue = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* stops propogation for this event
|
||||
*
|
||||
* @param {Event} e
|
||||
* @returns void
|
||||
*/
|
||||
function _stopPropagation(e) {
|
||||
if (e.stopPropagation) {
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
e.cancelBubble = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* actually calls the callback function
|
||||
*
|
||||
* if your callback function returns false this will use the jquery
|
||||
* convention - prevent default and stop propogation on the event
|
||||
*
|
||||
* @param {Function} callback
|
||||
* @param {Event} e
|
||||
* @returns void
|
||||
*/
|
||||
function _fireCallback(callback, e, combo, sequence) {
|
||||
|
||||
// if this event should not happen stop here
|
||||
if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback(e, combo) === false) {
|
||||
_preventDefault(e);
|
||||
_stopPropagation(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handles a character key event
|
||||
*
|
||||
* @param {string} character
|
||||
* @param {Array} modifiers
|
||||
* @param {Event} e
|
||||
* @returns void
|
||||
*/
|
||||
function _handleKey(character, modifiers, e) {
|
||||
var callbacks = _getMatches(character, modifiers, e),
|
||||
i,
|
||||
doNotReset = {},
|
||||
maxLevel = 0,
|
||||
processedSequenceCallback = false;
|
||||
|
||||
// Calculate the maxLevel for sequences so we can only execute the longest callback sequence
|
||||
for (i = 0; i < callbacks.length; ++i) {
|
||||
if (callbacks[i].seq) {
|
||||
maxLevel = Math.max(maxLevel, callbacks[i].level);
|
||||
}
|
||||
}
|
||||
|
||||
// loop through matching callbacks for this key event
|
||||
for (i = 0; i < callbacks.length; ++i) {
|
||||
|
||||
// fire for all sequence callbacks
|
||||
// this is because if for example you have multiple sequences
|
||||
// bound such as "g i" and "g t" they both need to fire the
|
||||
// callback for matching g cause otherwise you can only ever
|
||||
// match the first one
|
||||
if (callbacks[i].seq) {
|
||||
|
||||
// only fire callbacks for the maxLevel to prevent
|
||||
// subsequences from also firing
|
||||
//
|
||||
// for example 'a option b' should not cause 'option b' to fire
|
||||
// even though 'option b' is part of the other sequence
|
||||
//
|
||||
// any sequences that do not match here will be discarded
|
||||
// below by the _resetSequences call
|
||||
if (callbacks[i].level != maxLevel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
processedSequenceCallback = true;
|
||||
|
||||
// keep a list of which sequences were matches for later
|
||||
doNotReset[callbacks[i].seq] = 1;
|
||||
_fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq);
|
||||
continue;
|
||||
}
|
||||
|
||||
// if there were no sequence matches but we are still here
|
||||
// that means this is a regular match so we should fire that
|
||||
if (!processedSequenceCallback) {
|
||||
_fireCallback(callbacks[i].callback, e, callbacks[i].combo);
|
||||
}
|
||||
}
|
||||
|
||||
// if the key you pressed matches the type of sequence without
|
||||
// being a modifier (ie "keyup" or "keypress") then we should
|
||||
// reset all sequences that were not matched by this event
|
||||
//
|
||||
// this is so, for example, if you have the sequence "h a t" and you
|
||||
// type "h e a r t" it does not match. in this case the "e" will
|
||||
// cause the sequence to reset
|
||||
//
|
||||
// modifier keys are ignored because you can have a sequence
|
||||
// that contains modifiers such as "enter ctrl+space" and in most
|
||||
// cases the modifier key will be pressed before the next key
|
||||
//
|
||||
// also if you have a sequence such as "ctrl+b a" then pressing the
|
||||
// "b" key will trigger a "keypress" and a "keydown"
|
||||
//
|
||||
// the "keydown" is expected when there is a modifier, but the
|
||||
// "keypress" ends up matching the _nextExpectedAction since it occurs
|
||||
// after and that causes the sequence to reset
|
||||
//
|
||||
// we ignore keypresses in a sequence that directly follow a keydown
|
||||
// for the same character
|
||||
var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress;
|
||||
if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
|
||||
_resetSequences(doNotReset);
|
||||
}
|
||||
|
||||
_ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown';
|
||||
}
|
||||
|
||||
/**
|
||||
* handles a keydown event
|
||||
*
|
||||
* @param {Event} e
|
||||
* @returns void
|
||||
*/
|
||||
function _handleKeyEvent(e) {
|
||||
|
||||
// normalize e.which for key events
|
||||
// @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion
|
||||
if (typeof e.which !== 'number') {
|
||||
e.which = e.keyCode;
|
||||
}
|
||||
|
||||
var character = _characterFromEvent(e);
|
||||
|
||||
// no character found then stop
|
||||
if (!character) {
|
||||
return;
|
||||
}
|
||||
|
||||
// need to use === for the character check because the character can be 0
|
||||
if (e.type == 'keyup' && _ignoreNextKeyup === character) {
|
||||
_ignoreNextKeyup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Mousetrap.handleKey(character, _eventModifiers(e), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* determines if the keycode specified is a modifier key or not
|
||||
*
|
||||
* @param {string} key
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function _isModifier(key) {
|
||||
return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta';
|
||||
}
|
||||
|
||||
/**
|
||||
* called to set a 1 second timeout on the specified sequence
|
||||
*
|
||||
* this is so after each key press in the sequence you have 1 second
|
||||
* to press the next key before you have to start over
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
function _resetSequenceTimer() {
|
||||
clearTimeout(_resetTimer);
|
||||
_resetTimer = setTimeout(_resetSequences, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* reverses the map lookup so that we can look for specific keys
|
||||
* to see what can and can't use keypress
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
function _getReverseMap() {
|
||||
if (!_REVERSE_MAP) {
|
||||
_REVERSE_MAP = {};
|
||||
for (var key in _MAP) {
|
||||
|
||||
// pull out the numeric keypad from here cause keypress should
|
||||
// be able to detect the keys from the character
|
||||
if (key > 95 && key < 112) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_MAP.hasOwnProperty(key)) {
|
||||
_REVERSE_MAP[_MAP[key]] = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _REVERSE_MAP;
|
||||
}
|
||||
|
||||
/**
|
||||
* picks the best action based on the key combination
|
||||
*
|
||||
* @param {string} key - character for key
|
||||
* @param {Array} modifiers
|
||||
* @param {string=} action passed in
|
||||
*/
|
||||
function _pickBestAction(key, modifiers, action) {
|
||||
|
||||
// if no action was picked in we should try to pick the one
|
||||
// that we think would work best for this key
|
||||
if (!action) {
|
||||
action = _getReverseMap()[key] ? 'keydown' : 'keypress';
|
||||
}
|
||||
|
||||
// modifier keys don't work as expected with keypress,
|
||||
// switch to keydown
|
||||
if (action == 'keypress' && modifiers.length) {
|
||||
action = 'keydown';
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* binds a key sequence to an event
|
||||
*
|
||||
* @param {string} combo - combo specified in bind call
|
||||
* @param {Array} keys
|
||||
* @param {Function} callback
|
||||
* @param {string=} action
|
||||
* @returns void
|
||||
*/
|
||||
function _bindSequence(combo, keys, callback, action) {
|
||||
|
||||
// start off by adding a sequence level record for this combination
|
||||
// and setting the level to 0
|
||||
_sequenceLevels[combo] = 0;
|
||||
|
||||
/**
|
||||
* callback to increase the sequence level for this sequence and reset
|
||||
* all other sequences that were active
|
||||
*
|
||||
* @param {string} nextAction
|
||||
* @returns {Function}
|
||||
*/
|
||||
function _increaseSequence(nextAction) {
|
||||
return function() {
|
||||
_nextExpectedAction = nextAction;
|
||||
++_sequenceLevels[combo];
|
||||
_resetSequenceTimer();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* wraps the specified callback inside of another function in order
|
||||
* to reset all sequence counters as soon as this sequence is done
|
||||
*
|
||||
* @param {Event} e
|
||||
* @returns void
|
||||
*/
|
||||
function _callbackAndReset(e) {
|
||||
_fireCallback(callback, e, combo);
|
||||
|
||||
// we should ignore the next key up if the action is key down
|
||||
// or keypress. this is so if you finish a sequence and
|
||||
// release the key the final key will not trigger a keyup
|
||||
if (action !== 'keyup') {
|
||||
_ignoreNextKeyup = _characterFromEvent(e);
|
||||
}
|
||||
|
||||
// weird race condition if a sequence ends with the key
|
||||
// another sequence begins with
|
||||
setTimeout(_resetSequences, 10);
|
||||
}
|
||||
|
||||
// loop through keys one at a time and bind the appropriate callback
|
||||
// function. for any key leading up to the final one it should
|
||||
// increase the sequence. after the final, it should reset all sequences
|
||||
//
|
||||
// if an action is specified in the original bind call then that will
|
||||
// be used throughout. otherwise we will pass the action that the
|
||||
// next key in the sequence should match. this allows a sequence
|
||||
// to mix and match keypress and keydown events depending on which
|
||||
// ones are better suited to the key provided
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
var isFinal = i + 1 === keys.length;
|
||||
var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action);
|
||||
_bindSingle(keys[i], wrappedCallback, action, combo, i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from a string key combination to an array
|
||||
*
|
||||
* @param {string} combination like "command+shift+l"
|
||||
* @return {Array}
|
||||
*/
|
||||
function _keysFromString(combination) {
|
||||
if (combination === '+') {
|
||||
return ['+'];
|
||||
}
|
||||
|
||||
return combination.split('+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets info for a specific key combination
|
||||
*
|
||||
* @param {string} combination key combination ("command+s" or "a" or "*")
|
||||
* @param {string=} action
|
||||
* @returns {Object}
|
||||
*/
|
||||
function _getKeyInfo(combination, action) {
|
||||
var keys,
|
||||
key,
|
||||
i,
|
||||
modifiers = [];
|
||||
|
||||
// take the keys from this pattern and figure out what the actual
|
||||
// pattern is all about
|
||||
keys = _keysFromString(combination);
|
||||
|
||||
for (i = 0; i < keys.length; ++i) {
|
||||
key = keys[i];
|
||||
|
||||
// normalize key names
|
||||
if (_SPECIAL_ALIASES[key]) {
|
||||
key = _SPECIAL_ALIASES[key];
|
||||
}
|
||||
|
||||
// if this is not a keypress event then we should
|
||||
// be smart about using shift keys
|
||||
// this will only work for US keyboards however
|
||||
if (action && action != 'keypress' && _SHIFT_MAP[key]) {
|
||||
key = _SHIFT_MAP[key];
|
||||
modifiers.push('shift');
|
||||
}
|
||||
|
||||
// if this key is a modifier then add it to the list of modifiers
|
||||
if (_isModifier(key)) {
|
||||
modifiers.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
// depending on what the key combination is
|
||||
// we will try to pick the best event for it
|
||||
action = _pickBestAction(key, modifiers, action);
|
||||
|
||||
return {
|
||||
key: key,
|
||||
modifiers: modifiers,
|
||||
action: action
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* binds a single keyboard combination
|
||||
*
|
||||
* @param {string} combination
|
||||
* @param {Function} callback
|
||||
* @param {string=} action
|
||||
* @param {string=} sequenceName - name of sequence if part of sequence
|
||||
* @param {number=} level - what part of the sequence the command is
|
||||
* @returns void
|
||||
*/
|
||||
function _bindSingle(combination, callback, action, sequenceName, level) {
|
||||
|
||||
// store a direct mapped reference for use with Mousetrap.trigger
|
||||
_directMap[combination + ':' + action] = callback;
|
||||
|
||||
// make sure multiple spaces in a row become a single space
|
||||
combination = combination.replace(/\s+/g, ' ');
|
||||
|
||||
var sequence = combination.split(' '),
|
||||
info;
|
||||
|
||||
// if this pattern is a sequence of keys then run through this method
|
||||
// to reprocess each pattern one key at a time
|
||||
if (sequence.length > 1) {
|
||||
_bindSequence(combination, sequence, callback, action);
|
||||
return;
|
||||
}
|
||||
|
||||
info = _getKeyInfo(combination, action);
|
||||
|
||||
// make sure to initialize array if this is the first time
|
||||
// a callback is added for this key
|
||||
_callbacks[info.key] = _callbacks[info.key] || [];
|
||||
|
||||
// remove an existing match if there is one
|
||||
_getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level);
|
||||
|
||||
// add this call back to the array
|
||||
// if it is a sequence put it at the beginning
|
||||
// if not put it at the end
|
||||
//
|
||||
// this is important because the way these are processed expects
|
||||
// the sequence ones to come first
|
||||
_callbacks[info.key][sequenceName ? 'unshift' : 'push']({
|
||||
callback: callback,
|
||||
modifiers: info.modifiers,
|
||||
action: info.action,
|
||||
seq: sequenceName,
|
||||
level: level,
|
||||
combo: combination
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* binds multiple combinations to the same callback
|
||||
*
|
||||
* @param {Array} combinations
|
||||
* @param {Function} callback
|
||||
* @param {string|undefined} action
|
||||
* @returns void
|
||||
*/
|
||||
function _bindMultiple(combinations, callback, action) {
|
||||
for (var i = 0; i < combinations.length; ++i) {
|
||||
_bindSingle(combinations[i], callback, action);
|
||||
}
|
||||
}
|
||||
|
||||
// start!
|
||||
_addEvent(document, 'keypress', _handleKeyEvent);
|
||||
_addEvent(document, 'keydown', _handleKeyEvent);
|
||||
_addEvent(document, 'keyup', _handleKeyEvent);
|
||||
|
||||
var Mousetrap = {
|
||||
|
||||
/**
|
||||
* binds an event to mousetrap
|
||||
*
|
||||
* can be a single key, a combination of keys separated with +,
|
||||
* an array of keys, or a sequence of keys separated by spaces
|
||||
*
|
||||
* be sure to list the modifier keys first to make sure that the
|
||||
* correct key ends up getting bound (the last key in the pattern)
|
||||
*
|
||||
* @param {string|Array} keys
|
||||
* @param {Function} callback
|
||||
* @param {string=} action - 'keypress', 'keydown', or 'keyup'
|
||||
* @returns void
|
||||
*/
|
||||
bind: function(keys, callback, action) {
|
||||
keys = keys instanceof Array ? keys : [keys];
|
||||
_bindMultiple(keys, callback, action);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* unbinds an event to mousetrap
|
||||
*
|
||||
* the unbinding sets the callback function of the specified key combo
|
||||
* to an empty function and deletes the corresponding key in the
|
||||
* _directMap dict.
|
||||
*
|
||||
* TODO: actually remove this from the _callbacks dictionary instead
|
||||
* of binding an empty function
|
||||
*
|
||||
* the keycombo+action has to be exactly the same as
|
||||
* it was defined in the bind method
|
||||
*
|
||||
* @param {string|Array} keys
|
||||
* @param {string} action
|
||||
* @returns void
|
||||
*/
|
||||
unbind: function(keys, action) {
|
||||
return Mousetrap.bind(keys, function() {}, action);
|
||||
},
|
||||
|
||||
/**
|
||||
* triggers an event that has already been bound
|
||||
*
|
||||
* @param {string} keys
|
||||
* @param {string=} action
|
||||
* @returns void
|
||||
*/
|
||||
trigger: function(keys, action) {
|
||||
if (_directMap[keys + ':' + action]) {
|
||||
_directMap[keys + ':' + action]({}, keys);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* resets the library back to its initial state. this is useful
|
||||
* if you want to clear out the current keyboard shortcuts and bind
|
||||
* new ones - for example if you switch to another page
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
reset: function() {
|
||||
_callbacks = {};
|
||||
_directMap = {};
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* should we stop this event before firing off callbacks
|
||||
*
|
||||
* @param {Event} e
|
||||
* @param {Element} element
|
||||
* @return {boolean}
|
||||
*/
|
||||
stopCallback: function(e, element) {
|
||||
|
||||
// if the element has the class "mousetrap" then no need to stop
|
||||
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop for input, select, and textarea
|
||||
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
|
||||
},
|
||||
|
||||
/**
|
||||
* exposes _handleKey publicly so it can be overwritten by extensions
|
||||
*/
|
||||
handleKey: _handleKey
|
||||
};
|
||||
|
||||
// expose mousetrap to the global object
|
||||
window.Mousetrap = Mousetrap;
|
||||
|
||||
// expose mousetrap as an AMD module
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(Mousetrap);
|
||||
}
|
||||
}) (window, document);
|
||||
Vendored
-2068
File diff suppressed because it is too large
Load Diff
@@ -1,75 +0,0 @@
|
||||
.book {
|
||||
.book-body {
|
||||
position: fixed;
|
||||
top: @header-height;
|
||||
right: 0px;
|
||||
left: 0px;
|
||||
bottom: 0px;
|
||||
|
||||
background: @body-background;
|
||||
.transition(left 0.5s ease);
|
||||
|
||||
.body-inner {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
left: 0px;
|
||||
bottom: 0px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.page-wrapper {
|
||||
position: relative;
|
||||
outline: none;
|
||||
|
||||
.page-inner {
|
||||
font-family: @font-family-serif;
|
||||
max-width: 800px;
|
||||
margin: 0px auto;
|
||||
|
||||
section {
|
||||
margin: 0px 0px;
|
||||
padding: 5px 15px;
|
||||
|
||||
background: @page-background;
|
||||
border-radius: 2px;
|
||||
|
||||
font-size: 16px;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
.btn {
|
||||
border-radius: 0px;
|
||||
background: #eee;
|
||||
border: 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: @mobileMaxWidth) {
|
||||
overflow-y: auto;
|
||||
|
||||
.body-inner {
|
||||
position: static;
|
||||
padding-bottom: 20px;
|
||||
min-height: calc(~"100% - 57px")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.with-summary {
|
||||
@media (min-width: 800px) {
|
||||
.book-body {
|
||||
left: 250px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.without-animation {
|
||||
.book-body {
|
||||
.transition(none) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
@import "mixins.less";
|
||||
|
||||
@import "ebook/variables.less";
|
||||
@import "ebook/highlight.less";
|
||||
|
||||
.book-chapter {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
pre, blockquote {
|
||||
border: 1px solid #999;
|
||||
page-break-inside: avoid;
|
||||
background: #f1f1f1;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100% !important;
|
||||
page-break-inside: avoid;
|
||||
margin: 0px auto;
|
||||
}
|
||||
|
||||
.exercise, .quiz {
|
||||
margin: 1cm 0cm;
|
||||
padding: 0.4cm;
|
||||
page-break-inside: avoid;
|
||||
|
||||
border: 3px solid #ddd;
|
||||
|
||||
.exercise-header {
|
||||
margin-bottom: 0.4cm;
|
||||
padding-bottom: 0.2cm;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.question {
|
||||
margin-top: 0.4cm;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
||||
/* http://jmblog.github.io/color-themes-for-highlightjs */
|
||||
|
||||
/* Tomorrow Comment */
|
||||
.hljs-comment {
|
||||
color: hsl(207, 35%, 35%);
|
||||
.hljs-comment,
|
||||
.hljs-title {
|
||||
color: #8e908c;
|
||||
}
|
||||
|
||||
/* Tomorrow Red */
|
||||
@@ -27,9 +28,9 @@
|
||||
.hljs-pragma,
|
||||
.hljs-built_in,
|
||||
.hljs-literal,
|
||||
.hljs-constant,
|
||||
.hljs-function .hljs-title {
|
||||
color: hsl(50, 100%, 60%);
|
||||
.hljs-params,
|
||||
.hljs-constant {
|
||||
color: #f5871f;
|
||||
}
|
||||
|
||||
/* Tomorrow Yellow */
|
||||
@@ -45,7 +46,7 @@
|
||||
.hljs-header,
|
||||
.ruby .hljs-symbol,
|
||||
.xml .hljs-cdata {
|
||||
color: hsl(0, 100%, 70%);
|
||||
color: #718c00;
|
||||
}
|
||||
|
||||
/* Tomorrow Aqua */
|
||||
@@ -54,7 +55,7 @@
|
||||
}
|
||||
|
||||
/* Tomorrow Blue */
|
||||
.hljs-function .keyword,
|
||||
.hljs-function,
|
||||
.python .hljs-decorator,
|
||||
.python .hljs-title,
|
||||
.ruby .hljs-function .hljs-title,
|
||||
@@ -62,13 +63,13 @@
|
||||
.perl .hljs-sub,
|
||||
.javascript .hljs-title,
|
||||
.coffeescript .hljs-title {
|
||||
color: hsl(207, 70%, 60%);
|
||||
color: #4271ae;
|
||||
}
|
||||
|
||||
/* Tomorrow Purple */
|
||||
.hljs-keyword,
|
||||
.javascript .hljs-function {
|
||||
color: hsl(207, 95%, 70%);
|
||||
color: #8959a8;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
@@ -76,7 +77,6 @@
|
||||
background: white;
|
||||
color: #4d4d4c;
|
||||
padding: 0.5em;
|
||||
font-family: "Anonymous Pro", "Inconsolata", "Monaco", monospace;
|
||||
}
|
||||
|
||||
.coffeescript .javascript,
|
||||
@@ -87,4 +87,4 @@
|
||||
.xml .css,
|
||||
.xml .hljs-cdata {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
@font-size-base: 13px;
|
||||
@@ -4,4 +4,4 @@
|
||||
&:hover, &:focus {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
@import "vendors/bootstrap/bootstrap.less";
|
||||
@import "vendors/fontawesome/font-awesome.less";
|
||||
|
||||
@import "mixins.less";
|
||||
@import "variables.less";
|
||||
@import "fonts.less";
|
||||
|
||||
@import "page/highlight.less";
|
||||
|
||||
|
||||
@font-size-base: 13px;
|
||||
|
||||
|
||||
* {
|
||||
-webkit-overflow-scrolling: touch;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
-webkit-text-size-adjust: none;
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
text-rendering: optimizeLegibility;
|
||||
font-smoothing: antialiased;
|
||||
font-family: @font-family-base;
|
||||
}
|
||||
|
||||
|
||||
h1, h2, h3 {
|
||||
page-break-after: avoid;
|
||||
page-break-before: auto;
|
||||
}
|
||||
|
||||
h1 { font-size: floor(@font-size-base * 2.15); }
|
||||
h2 { font-size: floor(@font-size-base * 1.70); }
|
||||
h3 { font-size: ceil(@font-size-base * 1.25); }
|
||||
h4 { font-size: ceil(@font-size-base * 1); }
|
||||
h5 { font-size: ceil(@font-size-base * 0.85); }
|
||||
h6 { font-size: ceil(@font-size-base * 0.65); }
|
||||
|
||||
pre, blockquote {
|
||||
border: 1px solid #999;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100% !important;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
section {
|
||||
page-break-after: always;
|
||||
|
||||
&#cover {
|
||||
padding: 3cm 0cm;
|
||||
text-align: center;
|
||||
|
||||
h1 {
|
||||
font-size: 1.5cm;
|
||||
}
|
||||
}
|
||||
|
||||
&#summary {
|
||||
margin: 1.5cm;
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
ol {
|
||||
list-style: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
margin-left: 1cm;
|
||||
}
|
||||
|
||||
> ol {
|
||||
> li {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
article {
|
||||
margin-bottom: 1.5cm;
|
||||
|
||||
&.new-chapter {
|
||||
page-break-after: always;
|
||||
font-size: 0.6cm;
|
||||
text-align: center;
|
||||
padding: 3cm 0cm;
|
||||
|
||||
h1 {
|
||||
font-size: floor(@font-size-base * 2.7);
|
||||
}
|
||||
}
|
||||
|
||||
.exercise {
|
||||
margin: 1cm 0cm;
|
||||
padding: 0.4cm;
|
||||
page-break-inside: avoid;
|
||||
|
||||
border: 3px solid #ddd;
|
||||
|
||||
.exercise-header {
|
||||
margin-bottom: 0.4cm;
|
||||
padding-bottom: 0.2cm;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
@staticPath: "./";
|
||||
|
||||
// Sizes
|
||||
@mobileMaxWidth: 1240px;
|
||||
|
||||
// Header
|
||||
@header-height: 50px;
|
||||
@header-color: hsl(194, 5%, 52%);
|
||||
@header-background: white;
|
||||
@header-button-color: hsl(194, 5%, 52%);
|
||||
@header-button-hover-color: #151515;
|
||||
@header-button-hover-background: hsl(207, 15%, 95%);
|
||||
|
||||
// Body
|
||||
@body-background: white;
|
||||
@body-pagination-background: hsl(207, 15%, 95%);
|
||||
|
||||
// Sidebar
|
||||
@sidebar-width: 250px;
|
||||
@sidebar-color: hsl(207, 15%, 80%);
|
||||
@sidebar-background: hsl(207, 15%, 95%);
|
||||
|
||||
@sidebar-nested-padding: 10px;
|
||||
|
||||
@sidebar-search-padding: 6px;
|
||||
@sidebar-search-background: transparent;
|
||||
@sidebar-search-input-border-color: hsl(207, 15%, 80%);
|
||||
|
||||
@sidebar-divider-color: hsl(207, 15%, 85%);
|
||||
|
||||
@sidebar-link-color: hsl(207, 15%, 50%);
|
||||
@sidebar-link-background: transparent;
|
||||
@sidebar-link-hover-color: hsl(207, 100%, 50%);
|
||||
@sidebar-link-hover-background: transparent;
|
||||
|
||||
@sidebar-icon-color: @bar-progress-background;
|
||||
@sidebar-link-completed: hsl(207, 15%, 25%);
|
||||
@sidebar-link-completed-weight: normal;
|
||||
|
||||
// Page
|
||||
@page-background: white;
|
||||
|
||||
// Progress Bar
|
||||
@chapter-display: none;
|
||||
@chapter-size: 16px;
|
||||
|
||||
@progress-height: 0px;
|
||||
|
||||
@bar-height: 2px;
|
||||
@bar-left: @sidebar-width;
|
||||
@bar-right: 0;
|
||||
@bar-top: 50px;
|
||||
@bar-position: static;
|
||||
@bar-background: white;
|
||||
@bar-progress-background: hsl(120, 60%, 50%);
|
||||
|
||||
// Basics of a navbar
|
||||
@navbar-height: 50px;
|
||||
@navbar-margin-bottom: @line-height-computed;
|
||||
@navbar-default-border: #d5d5d5;
|
||||
@navbar-border-radius: 0px;
|
||||
@navbar-padding-horizontal: floor(@grid-gutter-width / 2);
|
||||
@navbar-padding-vertical: ((@navbar-height - @line-height-computed) / 2);
|
||||
|
||||
// Navbar brand label
|
||||
@navbar-default-color: #333;
|
||||
@navbar-default-link-color: #333;
|
||||
@navbar-default-brand-color: @navbar-default-link-color;
|
||||
@navbar-default-brand-hover-color: @navbar-default-link-color;
|
||||
@navbar-default-brand-hover-bg: transparent;
|
||||
|
||||
// Border Radius
|
||||
@border-radius-base: 1px;
|
||||
@border-radius-large: 3px;
|
||||
@border-radius-small: 1px;
|
||||
|
||||
// Fonts
|
||||
@font-family-serif: Merriweather, "EB Garamond", Georgia, serif;
|
||||
@font-family-sans: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
@font-family-base: @font-family-serif;
|
||||
|
||||
@FontPath: '@{staticPath}/fonts';
|
||||
@fa-font-path: "@{FontPath}/fontawesome";
|
||||
@@ -2,19 +2,19 @@
|
||||
@import "vendors/fontawesome/font-awesome.less";
|
||||
|
||||
@import "mixins.less";
|
||||
@import "variables.less";
|
||||
@import "fonts.less";
|
||||
|
||||
@import "book/highlight.less";
|
||||
@import "book/languages.less";
|
||||
@import "book/header.less";
|
||||
@import "book/summary.less";
|
||||
@import "book/body.less";
|
||||
@import "book/exercise.less";
|
||||
@import "book/quiz.less";
|
||||
@import "book/markdown.less";
|
||||
@import "book/progress.less";
|
||||
@import "book/navigation.less";
|
||||
@import "website/fonts.less";
|
||||
@import "website/variables.less";
|
||||
@import "website/languages.less";
|
||||
@import "website/header.less";
|
||||
@import "website/summary.less";
|
||||
@import "website/font-settings.less";
|
||||
@import "website/body.less";
|
||||
@import "website/exercise.less";
|
||||
@import "website/quiz.less";
|
||||
@import "website/markdown.less";
|
||||
@import "website/progress.less";
|
||||
@import "website/navigation.less";
|
||||
|
||||
* {
|
||||
-webkit-overflow-scrolling: touch;
|
||||
Executable
+137
@@ -0,0 +1,137 @@
|
||||
.book {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
.book-body {
|
||||
position: absolute;
|
||||
top: @header-height;
|
||||
right: 0px;
|
||||
left: 0px;
|
||||
bottom: 0px;
|
||||
|
||||
color: @page-color;
|
||||
background: @body-background;
|
||||
.transition(left 0.5s ease);
|
||||
|
||||
.body-inner {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
left: 0px;
|
||||
bottom: 0px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.page-wrapper {
|
||||
position: relative;
|
||||
outline: none;
|
||||
|
||||
.page-inner {
|
||||
max-width: 800px;
|
||||
margin: 0px auto;
|
||||
|
||||
section {
|
||||
margin: 0px 0px;
|
||||
padding: 5px 15px;
|
||||
|
||||
background: @page-background;
|
||||
border-radius: 2px;
|
||||
line-height: @content-line-height;
|
||||
font-size: @default-font-size;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
.btn {
|
||||
border-radius: 0px;
|
||||
background: #eee;
|
||||
border: 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: @mobileMaxWidth) {
|
||||
overflow-y: auto;
|
||||
|
||||
.body-inner {
|
||||
position: static;
|
||||
padding-bottom: 20px;
|
||||
min-height: calc(~"100% - 57px")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.with-summary {
|
||||
@media (min-width: @sidebar-breakpoint) {
|
||||
.book-body {
|
||||
left: 250px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.without-animation {
|
||||
.book-body {
|
||||
.transition(none) !important;
|
||||
}
|
||||
}
|
||||
&.color-theme-1{
|
||||
.book-body {
|
||||
color: @page-color-1;
|
||||
background: @body-background-1;
|
||||
.page-wrapper {
|
||||
.page-inner {
|
||||
section{
|
||||
background: @page-background-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
&.color-theme-2{
|
||||
.book-body {
|
||||
color: @page-color-2;
|
||||
background: @body-background-2;
|
||||
.page-wrapper {
|
||||
.page-inner {
|
||||
section{
|
||||
background: @page-background-2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.font-size-0 {
|
||||
.book-body {
|
||||
font-size:@s-font-size;
|
||||
}
|
||||
}
|
||||
&.font-size-1 {
|
||||
.book-body {
|
||||
font-size:@m-font-size;
|
||||
}
|
||||
}
|
||||
&.font-size-2 {
|
||||
.book-body {
|
||||
font-size:@l-font-size;
|
||||
}
|
||||
}
|
||||
&.font-size-3 {
|
||||
.book-body {
|
||||
font-size:@xl-font-size;
|
||||
}
|
||||
}
|
||||
&.font-size-4 {
|
||||
.book-body {
|
||||
font-size:@xxl-font-size;
|
||||
}
|
||||
}
|
||||
|
||||
&.font-family-0{
|
||||
font-family: @font-family-serif;
|
||||
}
|
||||
&.font-family-1{
|
||||
font-family: @font-family-sans;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
.book .book-body .page-wrapper .page-inner {
|
||||
section.exercise {
|
||||
padding: 0px;
|
||||
margin: 20px 0px;
|
||||
margin: 20px 15px;
|
||||
border: 3px solid #2f8cde;
|
||||
|
||||
.header {
|
||||
@@ -0,0 +1,159 @@
|
||||
.book-header{
|
||||
#font-settings-wrapper{
|
||||
position:relative;
|
||||
.dropdown-menu{
|
||||
background-color:@header-background;
|
||||
border-color:@sidebar-divider-color;
|
||||
padding: 0px;
|
||||
|
||||
.dropdown-caret{
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
left: -8px;
|
||||
width: 10px;
|
||||
height: 18px;
|
||||
float: left;
|
||||
overflow: hidden;
|
||||
.caret-outer{
|
||||
position: absolute;
|
||||
border-bottom: 9px solid transparent;
|
||||
border-top: 9px solid transparent;
|
||||
border-right: 9px solid rgba(0,0,0,0.1);
|
||||
height: auto;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: auto;
|
||||
display: inline-block;
|
||||
margin-left: -1px;
|
||||
}
|
||||
.caret-inner{
|
||||
position: absolute;
|
||||
display: inline-block;
|
||||
margin-left: -1px;
|
||||
top: 0;
|
||||
left: 1px;
|
||||
border-bottom: 9px solid transparent;
|
||||
border-top: 9px solid transparent;
|
||||
border-right: 9px solid @header-background;
|
||||
}
|
||||
}
|
||||
button{
|
||||
border: 0;
|
||||
background-color:transparent;
|
||||
color:@header-button-color;
|
||||
&:hover{
|
||||
color:@header-button-hover-color;
|
||||
background-color:@header-button-hover-background;
|
||||
}
|
||||
}
|
||||
#enlarge-font-size{
|
||||
width: 50%;
|
||||
font-size:1.4em;
|
||||
}
|
||||
#reduce-font-size{
|
||||
width: 50.5%;
|
||||
font-size:1em;
|
||||
}
|
||||
.btn-group-xs{
|
||||
.btn{
|
||||
width: 33.7%;
|
||||
padding: initial;
|
||||
}
|
||||
}
|
||||
.list-group{
|
||||
margin: 0px 0;
|
||||
|
||||
.list-group-item{
|
||||
cursor:pointer;
|
||||
background-color:transparent;
|
||||
border-color: @sidebar-divider-color;
|
||||
border-width: 1px 0 !important;
|
||||
|
||||
&:hover{
|
||||
color:@header-button-hover-color;
|
||||
background-color:@header-button-hover-background !important;
|
||||
}
|
||||
&.active{
|
||||
color:@header-button-hover-color;
|
||||
background-color:@header-button-hover-background !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
&.open{
|
||||
display:block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Theme 1
|
||||
*/
|
||||
|
||||
.color-theme-1{
|
||||
#font-settings-wrapper{
|
||||
.dropdown-menu{
|
||||
background-color:@sidebar-background-1;
|
||||
border-color:@sidebar-divider-color-1;
|
||||
.dropdown-caret .caret-inner{
|
||||
border-right: 9px solid @sidebar-background-1;
|
||||
}
|
||||
button{
|
||||
color:@header-button-color-1;
|
||||
&:hover{
|
||||
color:@header-button-hover-color-1;
|
||||
background-color:@header-button-hover-background-1;
|
||||
}
|
||||
}
|
||||
.list-group{
|
||||
.list-group-item{
|
||||
border-color:@sidebar-divider-color-1;
|
||||
&:hover{
|
||||
color:@header-button-hover-color-1;
|
||||
background-color:@header-button-hover-background-1 !important;
|
||||
}
|
||||
&.active{
|
||||
color:@header-button-hover-color-1;
|
||||
background-color:@header-button-hover-background-1 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Theme 2
|
||||
*/
|
||||
|
||||
.color-theme-2{
|
||||
#font-settings-wrapper{
|
||||
.dropdown-menu{
|
||||
background-color:@sidebar-background-2;
|
||||
border-color:@sidebar-divider-color-2;
|
||||
.dropdown-caret .caret-inner{
|
||||
border-right: 9px solid @sidebar-background-2;
|
||||
}
|
||||
button{
|
||||
color:@header-button-color-2;
|
||||
&:hover{
|
||||
color:@header-button-hover-color-2;
|
||||
background-color:@header-button-hover-background-2;
|
||||
}
|
||||
}
|
||||
.list-group{
|
||||
.list-group-item{
|
||||
border-color:@sidebar-divider-color-2;
|
||||
&:hover{
|
||||
color:@header-button-hover-color-2;
|
||||
background-color:@header-button-hover-background-2 !important;
|
||||
}
|
||||
&.active{
|
||||
color:@header-button-hover-color-2;
|
||||
background-color:@header-button-hover-background-2 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+8
-56
@@ -1,15 +1,3 @@
|
||||
@font-face {
|
||||
font-family: 'EB Garamond';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('EB Garamond 12 Regular'),url('@{FontPath}/ebgaramond/400.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'EB Garamond';
|
||||
font-style: italic;
|
||||
font-weight: 400i;
|
||||
src: local('EB Garamond 12 Italic'),url('@{FontPath}/ebgaramond/400i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: normal;
|
||||
@@ -19,7 +7,7 @@
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: italic;
|
||||
font-weight: 250i;
|
||||
font-weight: 250;
|
||||
src: local('Merriweather Light Italic'),url('@{FontPath}/merriweather/250i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
@@ -31,21 +19,9 @@
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: italic;
|
||||
font-weight: 400i;
|
||||
font-weight: 400;
|
||||
src: local('Merriweather Italic'),url('@{FontPath}/merriweather/400i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
src: local(''),url('@{FontPath}/merriweather/600.woff') format('woff');
|
||||
}
|
||||
/*@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: italic;
|
||||
font-weight: 600i;
|
||||
src: local(''),url('@{FontPath}/merriweather/600i.woff') format('woff');
|
||||
}*/
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: normal;
|
||||
@@ -55,7 +31,7 @@
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: italic;
|
||||
font-weight: 700i;
|
||||
font-weight: 700;
|
||||
src: local('Merriweather Bold Italic'),url('@{FontPath}/merriweather/700i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
@@ -67,33 +43,9 @@
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: italic;
|
||||
font-weight: 900i;
|
||||
font-weight: 900;
|
||||
src: local('Merriweather Heavy Italic'),url('@{FontPath}/merriweather/900i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Anonymous Pro';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Anonymous Pro'),url('@{FontPath}/anonymouspro/400.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Anonymous Pro';
|
||||
font-style: italic;
|
||||
font-weight: 400i;
|
||||
src: local('Anonymous Pro Italic'),url('@{FontPath}/anonymouspro/400i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Anonymous Pro';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Anonymous Pro Bold'),url('@{FontPath}/anonymouspro/700.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Anonymous Pro';
|
||||
font-style: italic;
|
||||
font-weight: 700i;
|
||||
src: local('Anonymous Pro Bold Italic'),url('@{FontPath}/anonymouspro/700i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
@@ -103,7 +55,7 @@
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: italic;
|
||||
font-weight: 300i;
|
||||
font-weight: 300;
|
||||
src: local('Open Sans Light Italic'),url('@{FontPath}/opensans/300i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
@@ -115,7 +67,7 @@
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: italic;
|
||||
font-weight: 400i;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans Italic'),url('@{FontPath}/opensans/400i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
@@ -127,7 +79,7 @@
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: italic;
|
||||
font-weight: 600i;
|
||||
font-weight: 600;
|
||||
src: local('Open Sans Semibold Italic'),url('@{FontPath}/opensans/600i.woff') format('woff');
|
||||
}
|
||||
@font-face {
|
||||
@@ -139,6 +91,6 @@
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: italic;
|
||||
font-weight: 700i;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold Italic'),url('@{FontPath}/opensans/700i.woff') format('woff');
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
.book-header {
|
||||
font-family: @font-family-sans;
|
||||
|
||||
position: fixed;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
overflow: visible;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
left: 0px;
|
||||
@@ -13,7 +13,7 @@
|
||||
font-size: 0.85em;
|
||||
color: @header-color;
|
||||
background: @header-background;
|
||||
box-shadow: 0 1px 2px hsla(200,10%,80%,0.6);
|
||||
border-bottom: 1px solid @header-border;
|
||||
|
||||
.btn {
|
||||
display: block;
|
||||
@@ -24,6 +24,7 @@
|
||||
text-transform: uppercase;
|
||||
line-height: @header-height;
|
||||
.box-shadow(none) !important;
|
||||
position:relative;
|
||||
|
||||
&:hover {
|
||||
position: relative;
|
||||
@@ -43,17 +44,35 @@
|
||||
padding-right: 200px;
|
||||
.transition(margin-left 0.5s ease);
|
||||
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
a, a:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
@media (max-width: 1000px) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
i {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.is-loading {
|
||||
.book-header h1 {
|
||||
i {
|
||||
display: inline-block;
|
||||
}
|
||||
a {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
&.with-summary {
|
||||
.book-header h1 {
|
||||
margin-left: 250px;
|
||||
@@ -64,4 +83,30 @@
|
||||
.transition(none) !important;
|
||||
}
|
||||
}
|
||||
&.color-theme-1{
|
||||
.book-header{
|
||||
color: @header-color-1;
|
||||
background: @header-background-1;
|
||||
.btn {
|
||||
color: @header-button-color-1;
|
||||
&:hover {
|
||||
color: @header-button-hover-color-1;
|
||||
background: @header-button-hover-background-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
&.color-theme-2{
|
||||
.book-header{
|
||||
color: @header-color-2;
|
||||
background: @header-background-2;
|
||||
.btn {
|
||||
color: @header-button-color-2;
|
||||
&:hover {
|
||||
color: @header-button-hover-color-2;
|
||||
background: @header-button-hover-background-2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/* Tomorrow Night Bright Theme */
|
||||
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
||||
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
||||
|
||||
/* Tomorrow Comment */
|
||||
.hljs-comment,
|
||||
.hljs-title {
|
||||
color: #969896;
|
||||
}
|
||||
|
||||
/* Tomorrow Red */
|
||||
.hljs-variable,
|
||||
.hljs-attribute,
|
||||
.hljs-tag,
|
||||
.hljs-regexp,
|
||||
.ruby .hljs-constant,
|
||||
.xml .hljs-tag .hljs-title,
|
||||
.xml .hljs-pi,
|
||||
.xml .hljs-doctype,
|
||||
.html .hljs-doctype,
|
||||
.css .hljs-id,
|
||||
.css .hljs-class,
|
||||
.css .hljs-pseudo {
|
||||
color: #d54e53;
|
||||
}
|
||||
|
||||
/* Tomorrow Orange */
|
||||
.hljs-number,
|
||||
.hljs-preprocessor,
|
||||
.hljs-pragma,
|
||||
.hljs-built_in,
|
||||
.hljs-literal,
|
||||
.hljs-params,
|
||||
.hljs-constant {
|
||||
color: #e78c45;
|
||||
}
|
||||
|
||||
/* Tomorrow Yellow */
|
||||
.ruby .hljs-class .hljs-title,
|
||||
.css .hljs-rules .hljs-attribute {
|
||||
color: #e7c547;
|
||||
}
|
||||
|
||||
/* Tomorrow Green */
|
||||
.hljs-string,
|
||||
.hljs-value,
|
||||
.hljs-inheritance,
|
||||
.hljs-header,
|
||||
.ruby .hljs-symbol,
|
||||
.xml .hljs-cdata {
|
||||
color: #b9ca4a;
|
||||
}
|
||||
|
||||
/* Tomorrow Aqua */
|
||||
.css .hljs-hexcolor {
|
||||
color: #70c0b1;
|
||||
}
|
||||
|
||||
/* Tomorrow Blue */
|
||||
.hljs-function,
|
||||
.python .hljs-decorator,
|
||||
.python .hljs-title,
|
||||
.ruby .hljs-function .hljs-title,
|
||||
.ruby .hljs-title .hljs-keyword,
|
||||
.perl .hljs-sub,
|
||||
.javascript .hljs-title,
|
||||
.coffeescript .hljs-title {
|
||||
color: #7aa6da;
|
||||
}
|
||||
|
||||
/* Tomorrow Purple */
|
||||
.hljs-keyword,
|
||||
.javascript .hljs-function {
|
||||
color: #c397d8;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
display: block;
|
||||
background: black;
|
||||
color: #eaeaea;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.coffeescript .javascript,
|
||||
.javascript .xml,
|
||||
.tex .hljs-formula,
|
||||
.xml .javascript,
|
||||
.xml .vbscript,
|
||||
.xml .css,
|
||||
.xml .hljs-cdata {
|
||||
opacity: 0.5;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
|
||||
Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull <sourdrums@gmail.com>
|
||||
|
||||
*/
|
||||
|
||||
.hljs {
|
||||
display: block;
|
||||
padding: 0.5em;
|
||||
background: #fdf6e3;
|
||||
color: #657b83;
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-template_comment,
|
||||
.diff .hljs-header,
|
||||
.hljs-doctype,
|
||||
.hljs-pi,
|
||||
.lisp .hljs-string,
|
||||
.hljs-javadoc {
|
||||
color: #93a1a1;
|
||||
}
|
||||
|
||||
/* Solarized Green */
|
||||
.hljs-keyword,
|
||||
.hljs-winutils,
|
||||
.method,
|
||||
.hljs-addition,
|
||||
.css .hljs-tag,
|
||||
.hljs-request,
|
||||
.hljs-status,
|
||||
.nginx .hljs-title {
|
||||
color: #859900;
|
||||
}
|
||||
|
||||
/* Solarized Cyan */
|
||||
.hljs-number,
|
||||
.hljs-command,
|
||||
.hljs-string,
|
||||
.hljs-tag .hljs-value,
|
||||
.hljs-rules .hljs-value,
|
||||
.hljs-phpdoc,
|
||||
.tex .hljs-formula,
|
||||
.hljs-regexp,
|
||||
.hljs-hexcolor,
|
||||
.hljs-link_url {
|
||||
color: #2aa198;
|
||||
}
|
||||
|
||||
/* Solarized Blue */
|
||||
.hljs-title,
|
||||
.hljs-localvars,
|
||||
.hljs-chunk,
|
||||
.hljs-decorator,
|
||||
.hljs-built_in,
|
||||
.hljs-identifier,
|
||||
.vhdl .hljs-literal,
|
||||
.hljs-id,
|
||||
.css .hljs-function {
|
||||
color: #268bd2;
|
||||
}
|
||||
|
||||
/* Solarized Yellow */
|
||||
.hljs-attribute,
|
||||
.hljs-variable,
|
||||
.lisp .hljs-body,
|
||||
.smalltalk .hljs-number,
|
||||
.hljs-constant,
|
||||
.hljs-class .hljs-title,
|
||||
.hljs-parent,
|
||||
.haskell .hljs-type,
|
||||
.hljs-link_reference {
|
||||
color: #b58900;
|
||||
}
|
||||
|
||||
/* Solarized Orange */
|
||||
.hljs-preprocessor,
|
||||
.hljs-preprocessor .hljs-keyword,
|
||||
.hljs-pragma,
|
||||
.hljs-shebang,
|
||||
.hljs-symbol,
|
||||
.hljs-symbol .hljs-string,
|
||||
.diff .hljs-change,
|
||||
.hljs-special,
|
||||
.hljs-attr_selector,
|
||||
.hljs-subst,
|
||||
.hljs-cdata,
|
||||
.clojure .hljs-title,
|
||||
.css .hljs-pseudo,
|
||||
.hljs-header {
|
||||
color: #cb4b16;
|
||||
}
|
||||
|
||||
/* Solarized Red */
|
||||
.hljs-deletion,
|
||||
.hljs-important {
|
||||
color: #dc322f;
|
||||
}
|
||||
|
||||
/* Solarized Violet */
|
||||
.hljs-link_label {
|
||||
color: #6c71c4;
|
||||
}
|
||||
|
||||
.tex .hljs-formula {
|
||||
background: #eee8d5;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user