summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-08-08 18:50:07 -0700
committerSamy Pessé <samypesse@gmail.com>2014-08-11 07:36:46 -0700
commit78c68c7b9efd98139182c88580186d2456b1bec7 (patch)
tree3a68e5ca30987f0a9190b5140ff58e416e7dc829
parentd914eae40a9730d76295750ac47ebed9fe4f7146 (diff)
downloadgitbook-78c68c7b9efd98139182c88580186d2456b1bec7.zip
gitbook-78c68c7b9efd98139182c88580186d2456b1bec7.tar.gz
gitbook-78c68c7b9efd98139182c88580186d2456b1bec7.tar.bz2
Remove config for github urls
-rw-r--r--lib/generate/config.js91
-rw-r--r--lib/generate/index.js69
-rw-r--r--lib/parse/git.js56
-rw-r--r--lib/parse/index.js3
-rw-r--r--theme/templates/includes/book/exercise.html4
-rw-r--r--theme/templates/includes/book/header.html4
-rw-r--r--theme/templates/includes/book/quiz.html4
-rw-r--r--theme/templates/includes/book/summary.html28
8 files changed, 115 insertions, 144 deletions
diff --git a/lib/generate/config.js b/lib/generate/config.js
new file mode 100644
index 0000000..798bedc
--- /dev/null
+++ b/lib/generate/config.js
@@ -0,0 +1,91 @@
+var path = require('path');
+
+// Default configuration for gitbook
+module.exports = {
+ // 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,
+
+ // Plugins list, can contain "-name" for removing default plugins
+ "plugins": [],
+
+ // Global configuration for plugins
+ "pluginsConfig": {
+ "fontSettings": {
+ "theme": null, //"sepia", "night" or "white",
+ "family": "serif",// "serif" or "sans",
+ "size": 2 // 1 - 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": path.resolve(__dirname, '../../theme'),
+
+ // 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
+ }
+ }
+};
+
diff --git a/lib/generate/index.js b/lib/generate/index.js
index 53de646..362d613 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -7,6 +7,7 @@ var swig = require('./template');
var fs = require("./fs");
var parse = require("../parse");
var Plugin = require("./plugin");
+var defaultConfig = require("./config");
var generators = {
"site": require("./site"),
@@ -25,7 +26,7 @@ var containsFiles = function(dir, files) {
.then(_.all);
};
-// TEst if generator exists
+// Test if generator exists
var checkGenerator = function(options) {
if (!generators[options.generator]) {
return Q.reject(new Error("Invalid generator (availables are: "+_.keys(generators).join(", ")+")"));
@@ -48,40 +49,7 @@ var loadGenerator = function(options) {
var generate = function(options) {
// Set defaults to options
- options = _.defaults(options || {}, {
- // Folders to use
- "input": null,
- "output": null,
-
- // Config file (relative to input)
- "configFile": "book",
-
- // Output generator
- "generator": "site",
-
- // Book title, keyword, description
- "title": null,
- "description": null,
-
- // Origin github repository id
- "github": null,
- "githubHost": 'https://github.com/',
-
- // Theming
- "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,
- }
- });
+ options = _.merge(options || {}, defaultConfig, _.defaults);
// Validate options
if (!options.input) {
@@ -217,37 +185,6 @@ var generateBook = function(options) {
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);
})
diff --git a/lib/parse/git.js b/lib/parse/git.js
deleted file mode 100644
index 18a7cd3..0000000
--- a/lib/parse/git.js
+++ /dev/null
@@ -1,56 +0,0 @@
-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
-};
diff --git a/lib/parse/index.js b/lib/parse/index.js
index bb7779f..0ebb03a 100644
--- a/lib/parse/index.js
+++ b/lib/parse/index.js
@@ -5,6 +5,5 @@ module.exports = {
lex: require('./lex'),
progress: require('./progress'),
navigation: require('./navigation'),
- readme: require('./readme'),
- git: require('./git')
+ readme: require('./readme')
};
diff --git a/theme/templates/includes/book/exercise.html b/theme/templates/includes/book/exercise.html
index faefbb7..cb1c4ed 100644
--- a/theme/templates/includes/book/exercise.html
+++ b/theme/templates/includes/book/exercise.html
@@ -23,7 +23,7 @@
<div class="btn-group btn-group-justified">
<a href="#" class="btn btn-default action-submit">Submit</a>
<a href="#" class="btn btn-default action-solution">Solution</a>
- {% if githubId %}
- <a href="{{ githubHost }}{{ githubId }}/issues/new" target="_blank" class="btn btn-default">Have a Question?</a>
+ {% if options.links.issues %}
+ <a href="{{ options.links.issues }}" target="_blank" class="btn btn-default">Have a Question?</a>
{% endif %}
</div>
diff --git a/theme/templates/includes/book/header.html b/theme/templates/includes/book/header.html
index 9b36af8..43898f9 100644
--- a/theme/templates/includes/book/header.html
+++ b/theme/templates/includes/book/header.html
@@ -1,8 +1,8 @@
<div class="book-header">
<!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
- {% if options.links.home !== false and (options.links.home != null or githubId) %}
- <a href="{{ options.links.home|default(githubHost+githubId) }}" target="_blank" class="btn pull-left home-bookmark" aria-label="GitHub home"><i class="fa fa-bookmark-o"></i></a>
+ {% if options.links.home %}
+ <a href="{{ options.links.home }}" target="_blank" class="btn pull-left home-bookmark" aria-label="GitHub home"><i class="fa fa-bookmark-o"></i></a>
{% endif %}
<a href="#" class="btn pull-left toggle-search" aria-label="Toggle search"><i class="fa fa-search"></i></a>
<span id="font-settings-wrapper">
diff --git a/theme/templates/includes/book/quiz.html b/theme/templates/includes/book/quiz.html
index c315a16..3c10ffc 100644
--- a/theme/templates/includes/book/quiz.html
+++ b/theme/templates/includes/book/quiz.html
@@ -37,7 +37,7 @@
<div class="btn-group btn-group-justified">
<a href="#" class="btn btn-default action-submit">Submit</a>
<a href="#" class="btn btn-default action-solution">Solution</a>
- {% if githubId %}
- <a href="{{ githubHost }}{{ githubId }}/issues/new" target="_blank" class="btn btn-default">Have a Question?</a>
+ {% if options.links.issues %}
+ <a href="{{ options.links.issues }}" target="_blank" class="btn btn-default">Have a Question?</a>
{% endif %}
</div>
diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html
index 3eda4cb..b110c00 100644
--- a/theme/templates/includes/book/summary.html
+++ b/theme/templates/includes/book/summary.html
@@ -38,35 +38,35 @@
</div>
<ul class="summary">
{% set _divider = false %}
- {% if options.links.about !== false && (options.links.about || githubId) %}
+ {% if options.links.about %}
{% set _divider = true %}
<li>
- <a href="{{ options.links.about|default(githubHost+githubAuthor) }}" target="blank" class="author-link">About the author</a>
+ <a href="{{ options.links.about }}" target="blank" class="author-link">About the author</a>
</li>
{% endif %}
- {% if options.links.issues !== false && (options.links.issues || githubId) %}
+ {% if options.links.issues %}
{% set _divider = true %}
<li>
- <a href="{{ options.links.issues|default(githubHost+githubId+"/issues") }}" target="blank" class="issues-link">Questions and Issues</a>
+ <a href="{{ options.links.issues }}" target="blank" class="issues-link">Questions and Issues</a>
</li>
{% endif %}
- {% if options.links.contribute !== false && (options.links.contribute || githubId) %}
+ {% if options.links.contribute %}
{% set _divider = true %}
<li>
- <a href="{{ options.links.contribute|default(githubHost+githubId+"/edit/master/"+_input) }}" target="blank" class="contribute-link">Edit and Contribute</a>
+ <a href="{{ options.links.contribute }}" target="blank" class="contribute-link">Contribute to this book</a>
</li>
{% endif %}
- {% if options.links.custom %}
- {% for link in options.links.custom %}
- {% set _divider = true %}
- <li>
- <a href="{{ options.links.custom[loop.key] }}" target="blank" class="custom-link">{{ loop.key }}</a>
- </li>
- {% endfor %}
- {% endif %}
+ {% if options.links.custom %}
+ {% for link in options.links.custom %}
+ {% set _divider = true %}
+ <li>
+ <a href="{{ options.links.custom[loop.key] }}" target="blank" class="custom-link">{{ loop.key }}</a>
+ </li>
+ {% endfor %}
+ {% endif %}
{% if _divider %}
<li class="divider"></li>