mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 18:13:29 +00:00
Fix #91: Extract defaults title and description from README.md
This commit is contained in:
+2
-16
@@ -24,27 +24,13 @@ var makeBuildFunc = function(converter) {
|
||||
return null;
|
||||
})
|
||||
.then(function(repoID) {
|
||||
var title = options.title;
|
||||
var githubID = options.github || repoID;
|
||||
|
||||
if (!title && !githubID) {
|
||||
throw new Error('Needs either a title or a githubID (username/repo).\n'+
|
||||
' If using github, either set repo origin to a github repo or use the -g flag.\n'+
|
||||
' For title, use the -t flag.');
|
||||
} else if (!title) {
|
||||
var parts = githubID.split('/', 2);
|
||||
var user = parts[0], repo = parts[1];
|
||||
|
||||
title = utils.titleCase(repo);
|
||||
}
|
||||
|
||||
return converter(
|
||||
_.extend(options || {}, {
|
||||
input: dir,
|
||||
output: outputDir,
|
||||
title: title,
|
||||
title: options.title,
|
||||
description: options.intro,
|
||||
github: githubID,
|
||||
github: options.github || repoID,
|
||||
githubHost: options.githubHost,
|
||||
generator: options.format,
|
||||
theme: options.theme
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ 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, defaults to repo name')
|
||||
.option('-i, --intro <intro>', 'Description of the book to generate')
|
||||
.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');
|
||||
|
||||
+24
-8
@@ -15,6 +15,8 @@ var generators = {
|
||||
"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
|
||||
@@ -33,7 +35,7 @@ var generate = function(options) {
|
||||
|
||||
// Book title, keyword, description
|
||||
title: null,
|
||||
description: "Book generated using GitBook",
|
||||
description: null,
|
||||
|
||||
// Origin github repository id
|
||||
github: null,
|
||||
@@ -43,8 +45,8 @@ var generate = function(options) {
|
||||
theme: path.resolve(__dirname, '../../theme')
|
||||
});
|
||||
|
||||
if (!options.title || !options.input) {
|
||||
return Q.reject(new Error("Need options: title, input"));
|
||||
if (!options.input) {
|
||||
return Q.reject(new Error("Need option input (book input directory)"));
|
||||
}
|
||||
|
||||
if (!generators[options.generator]) {
|
||||
@@ -103,14 +105,28 @@ var generate = function(options) {
|
||||
return Q.reject(new Error("Invalid gitbook repository, need SUMMARY.md and README.md"));
|
||||
} else {
|
||||
// Generate the book
|
||||
return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
|
||||
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(_summary) {
|
||||
options.summary = parse.summary(_summary);
|
||||
.then(function() {
|
||||
return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
|
||||
.then(function(_summary) {
|
||||
options.summary = parse.summary(_summary);
|
||||
|
||||
// Parse navigation
|
||||
options.navigation = parse.navigation(options.summary);
|
||||
// Parse navigation
|
||||
options.navigation = parse.navigation(options.summary);
|
||||
});
|
||||
})
|
||||
|
||||
// Copy file and replace markdown file
|
||||
|
||||
Reference in New Issue
Block a user