mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Don't copy assets for ebook to website bundle
This commit is contained in:
@@ -24,8 +24,5 @@ build/Release
|
||||
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
|
||||
theme/javascript/vendors
|
||||
theme/vendors
|
||||
|
||||
# vim swapfile
|
||||
*.swp
|
||||
|
||||
+18
-5
@@ -1,4 +1,6 @@
|
||||
var _ = require('lodash');
|
||||
var gulp = require('gulp');
|
||||
var gutil = require('gulp-util');
|
||||
var less = require('gulp-less');
|
||||
var rename = require('gulp-rename');
|
||||
var minifyCSS = require('gulp-minify-css');
|
||||
@@ -7,13 +9,24 @@ var mergeStream = require('merge-stream');
|
||||
var source = require('vinyl-source-stream');
|
||||
|
||||
gulp.task('css', function() {
|
||||
return mergeStream(
|
||||
gulp.src('theme/stylesheets/*.less')
|
||||
var merged = mergeStream();
|
||||
|
||||
_.each({
|
||||
'ebook.less': 'ebook/ebook.css',
|
||||
'pdf.less': 'ebook/pdf.css',
|
||||
'mobi.less': 'ebook/mobi.css',
|
||||
'epub.less': 'ebook/epub.css',
|
||||
'website.less': 'website/style.css'
|
||||
}, function(out, input) {
|
||||
gutil.log('compiling', input, 'into', out);
|
||||
merged.add(gulp.src('theme/stylesheets/'+input)
|
||||
.pipe(less())
|
||||
.pipe(minifyCSS())
|
||||
//.pipe(rename('style.css'))
|
||||
.pipe(gulp.dest('theme/assets/'))
|
||||
);
|
||||
.pipe(rename(out))
|
||||
.pipe(gulp.dest('theme/assets/')));
|
||||
});
|
||||
|
||||
return merged;
|
||||
});
|
||||
|
||||
gulp.task('js', function() {
|
||||
|
||||
+38
-38
@@ -1,18 +1,18 @@
|
||||
var util = require("util");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
var util = require('util');
|
||||
var path = require('path');
|
||||
var Q = require('q');
|
||||
var _ = require('lodash');
|
||||
|
||||
var nunjucks = require("nunjucks");
|
||||
var AutoEscapeExtension = require("nunjucks-autoescape")(nunjucks);
|
||||
var FilterExtension = require("nunjucks-filter")(nunjucks);
|
||||
var nunjucks = require('nunjucks');
|
||||
var AutoEscapeExtension = require('nunjucks-autoescape')(nunjucks);
|
||||
var FilterExtension = require('nunjucks-filter')(nunjucks);
|
||||
|
||||
var fs = require("../utils/fs");
|
||||
var BaseGenerator = require("../generator");
|
||||
var links = require("../utils/links");
|
||||
var i18n = require("../utils/i18n");
|
||||
var fs = require('../utils/fs');
|
||||
var BaseGenerator = require('../generator');
|
||||
var links = require('../utils/links');
|
||||
var i18n = require('../utils/i18n');
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
var pkg = require('../../package.json');
|
||||
|
||||
var Generator = function() {
|
||||
BaseGenerator.apply(this, arguments);
|
||||
@@ -21,10 +21,10 @@ var Generator = function() {
|
||||
this.revision = new Date();
|
||||
|
||||
// Resources namespace
|
||||
this.namespace = "website";
|
||||
this.namespace = 'website';
|
||||
|
||||
// Style to integrates in the output
|
||||
this.styles = ["website"];
|
||||
this.styles = ['website'];
|
||||
|
||||
// Convert images (svg -> png)
|
||||
this.convertImages = false;
|
||||
@@ -63,9 +63,9 @@ Generator.prototype.prepareStyles = function() {
|
||||
|
||||
// Prepare templates
|
||||
Generator.prototype.prepareTemplates = function() {
|
||||
this.templates.page = this.book.plugins.template("site:page") || path.resolve(this.options.theme, "templates/website/page.html");
|
||||
this.templates.langs = this.book.plugins.template("site:langs") || path.resolve(this.options.theme, "templates/website/langs.html");
|
||||
this.templates.glossary = this.book.plugins.template("site:glossary") || path.resolve(this.options.theme, "templates/website/glossary.html");
|
||||
this.templates.page = this.book.plugins.template('site:page') || path.resolve(this.options.theme, 'templates/website/page.html');
|
||||
this.templates.langs = this.book.plugins.template('site:langs') || path.resolve(this.options.theme, 'templates/website/langs.html');
|
||||
this.templates.glossary = this.book.plugins.template('site:glossary') || path.resolve(this.options.theme, 'templates/website/glossary.html');
|
||||
|
||||
return Q();
|
||||
};
|
||||
@@ -79,7 +79,7 @@ Generator.prototype.prepareTemplateEngine = function() {
|
||||
var language = that.book.config.normalizeLanguage();
|
||||
|
||||
if (!i18n.hasLocale(language)) {
|
||||
that.book.log.warn.ln("Language '"+language+"' is not available as a layout locales (en, "+i18n.getLocales().join(", ")+")");
|
||||
that.book.log.warn.ln('Language "'+language+'" is not available as a layout locales (en, '+i18n.getLocales().join(', ')+')');
|
||||
}
|
||||
|
||||
var folders = _.chain(that.templates)
|
||||
@@ -96,14 +96,14 @@ Generator.prototype.prepareTemplateEngine = function() {
|
||||
);
|
||||
|
||||
// Add filter
|
||||
that.env.addFilter("contentLink", that.book.contentLink.bind(that.book));
|
||||
that.env.addFilter("lvl", function(lvl) {
|
||||
return lvl.split(".").length;
|
||||
that.env.addFilter('contentLink', that.book.contentLink.bind(that.book));
|
||||
that.env.addFilter('lvl', function(lvl) {
|
||||
return lvl.split('.').length;
|
||||
});
|
||||
|
||||
// Add extension
|
||||
that.env.addExtension("AutoEscapeExtension", new AutoEscapeExtension(that.env));
|
||||
that.env.addExtension("FilterExtension", new FilterExtension(that.env));
|
||||
that.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(that.env));
|
||||
that.env.addExtension('FilterExtension', new FilterExtension(that.env));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -122,20 +122,20 @@ Generator.prototype.convertFile = function(input) {
|
||||
return that.book.parsePage(input, {
|
||||
convertImages: that.convertImages,
|
||||
interpolateTemplate: function(page) {
|
||||
return that.callHook("page:before", page);
|
||||
return that.callHook('page:before', page);
|
||||
},
|
||||
interpolateContent: function(page) {
|
||||
return that.callHook("page", page);
|
||||
return that.callHook('page', page);
|
||||
}
|
||||
})
|
||||
.then(function(page) {
|
||||
var relativeOutput = that.book.contentPath(page.path);
|
||||
var output = path.join(that.options.output, relativeOutput);
|
||||
|
||||
var basePath = path.relative(path.dirname(output), that.options.output) || ".";
|
||||
if (process.platform === "win32") basePath = basePath.replace(/\\/g, "/");
|
||||
var basePath = path.relative(path.dirname(output), that.options.output) || '.';
|
||||
if (process.platform === 'win32') basePath = basePath.replace(/\\/g, '/');
|
||||
|
||||
that.book.log.debug.ln("write parsed file", page.path, "to", relativeOutput);
|
||||
that.book.log.debug.ln('write parsed file', page.path, 'to', relativeOutput);
|
||||
|
||||
return that._writeTemplate(that.templates.page, {
|
||||
progress: page.progress,
|
||||
@@ -144,7 +144,7 @@ Generator.prototype.convertFile = function(input) {
|
||||
content: page.sections,
|
||||
|
||||
basePath: basePath,
|
||||
staticBase: links.join(basePath, "gitbook")
|
||||
staticBase: links.join(basePath, 'gitbook')
|
||||
}, output);
|
||||
});
|
||||
};
|
||||
@@ -155,7 +155,7 @@ Generator.prototype.writeLangsIndex = function() {
|
||||
|
||||
return this._writeTemplate(this.templates.langs, {
|
||||
langs: this.book.langs
|
||||
}, path.join(this.options.output, "index.html"));
|
||||
}, path.join(this.options.output, 'index.html'));
|
||||
};
|
||||
|
||||
// Write glossary
|
||||
@@ -163,7 +163,7 @@ Generator.prototype.writeGlossary = function() {
|
||||
// No glossary
|
||||
if (this.book.glossary.length === 0) return Q();
|
||||
|
||||
return this._writeTemplate(this.templates.glossary, {}, path.join(this.options.output, "GLOSSARY.html"));
|
||||
return this._writeTemplate(this.templates.glossary, {}, path.join(this.options.output, 'GLOSSARY.html'));
|
||||
};
|
||||
|
||||
// Convert a page into a normalized data set
|
||||
@@ -180,7 +180,7 @@ Generator.prototype.normalizePage = function(page) {
|
||||
|
||||
return Q()
|
||||
.then(function() {
|
||||
return _callHook("page");
|
||||
return _callHook('page');
|
||||
})
|
||||
.then(function() {
|
||||
return page;
|
||||
@@ -222,10 +222,10 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate)
|
||||
|
||||
options: that.options,
|
||||
|
||||
basePath: ".",
|
||||
staticBase: path.join(".", "gitbook"),
|
||||
basePath: '.',
|
||||
staticBase: path.join('.', 'gitbook'),
|
||||
|
||||
"__": that.book.i18n.bind(that.book)
|
||||
'__': that.book.i18n.bind(that.book)
|
||||
}, options)
|
||||
);
|
||||
})
|
||||
@@ -244,15 +244,15 @@ Generator.prototype.copyAssets = function() {
|
||||
|
||||
// Copy gitbook assets
|
||||
return fs.copy(
|
||||
path.join(that.options.theme, "assets"),
|
||||
path.join(that.options.output, "gitbook")
|
||||
path.join(that.options.theme, 'assets/'+this.namespace),
|
||||
path.join(that.options.output, 'gitbook')
|
||||
)
|
||||
|
||||
// Copy plugins assets
|
||||
.then(function() {
|
||||
return Q.all(
|
||||
_.map(that.book.plugins.list, function(plugin) {
|
||||
var pluginAssets = path.join(that.options.output, "gitbook/plugins/", plugin.name);
|
||||
var pluginAssets = path.join(that.options.output, 'gitbook/plugins/', plugin.name);
|
||||
return plugin.copyAssets(pluginAssets, that.namespace);
|
||||
})
|
||||
);
|
||||
|
||||
+23
-24
@@ -1,10 +1,10 @@
|
||||
var _ = require("lodash");
|
||||
var Q = require("q");
|
||||
var tmp = require("tmp");
|
||||
var path = require("path");
|
||||
var fs = require("graceful-fs");
|
||||
var fsExtra = require("fs-extra");
|
||||
var Ignore = require("fstream-ignore");
|
||||
var _ = require('lodash');
|
||||
var Q = require('q');
|
||||
var tmp = require('tmp');
|
||||
var path = require('path');
|
||||
var fs = require('graceful-fs');
|
||||
var fsExtra = require('fs-extra');
|
||||
var Ignore = require('fstream-ignore');
|
||||
|
||||
var fsUtils = {
|
||||
tmp: {
|
||||
@@ -33,7 +33,7 @@ var fsUtils = {
|
||||
existsSync: fs.existsSync.bind(fs),
|
||||
readFileSync: fs.readFileSync.bind(fs),
|
||||
clean: cleanFolder,
|
||||
getUniqueFilename: getUniqueFilename,
|
||||
getUniqueFilename: getUniqueFilename
|
||||
};
|
||||
|
||||
// Write a file
|
||||
@@ -57,14 +57,14 @@ function writeStream(filename, st) {
|
||||
|
||||
var wstream = fs.createWriteStream(filename);
|
||||
|
||||
wstream.on("finish", function () {
|
||||
wstream.on('finish', function () {
|
||||
d.resolve();
|
||||
});
|
||||
wstream.on("error", function (err) {
|
||||
wstream.on('error', function (err) {
|
||||
d.reject(err);
|
||||
});
|
||||
|
||||
st.on("error", function(err) {
|
||||
st.on('error', function(err) {
|
||||
d.reject(err);
|
||||
});
|
||||
|
||||
@@ -77,7 +77,7 @@ function writeStream(filename, st) {
|
||||
function getUniqueFilename(base, filename) {
|
||||
if (!filename) {
|
||||
filename = base;
|
||||
base = "/";
|
||||
base = '/';
|
||||
}
|
||||
|
||||
filename = path.resolve(base, filename);
|
||||
@@ -87,9 +87,8 @@ function getUniqueFilename(base, filename) {
|
||||
var _filename = filename+ext;
|
||||
|
||||
var i = 0;
|
||||
while (1) {
|
||||
if (!fs.existsSync(filename)) break;
|
||||
_filename = filename+"_"+i+ext;
|
||||
while (fs.existsSync(filename)) {
|
||||
_filename = filename+'_'+i+ext;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
@@ -115,20 +114,20 @@ function listFiles(root, options) {
|
||||
});
|
||||
|
||||
// Add extra rules to ignore common folders
|
||||
ig.addIgnoreRules(options.ignoreRules, "__custom_stuff");
|
||||
ig.addIgnoreRules(options.ignoreRules, '__custom_stuff');
|
||||
|
||||
// Push each file to our list
|
||||
ig.on("child", function (c) {
|
||||
ig.on('child', function (c) {
|
||||
files.push(
|
||||
c.path.substr(c.root.path.length + 1) + (c.props.Directory === true ? "/" : "")
|
||||
c.path.substr(c.root.path.length + 1) + (c.props.Directory === true ? '/' : '')
|
||||
);
|
||||
});
|
||||
|
||||
ig.on("end", function() {
|
||||
ig.on('end', function() {
|
||||
// Normalize paths on Windows
|
||||
if(process.platform === "win32") {
|
||||
if(process.platform === 'win32') {
|
||||
return d.resolve(files.map(function(file) {
|
||||
return file.replace(/\\/g, "/");
|
||||
return file.replace(/\\/g, '/');
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -136,7 +135,7 @@ function listFiles(root, options) {
|
||||
return d.resolve(files);
|
||||
});
|
||||
|
||||
ig.on("error", d.reject);
|
||||
ig.on('error', d.reject);
|
||||
|
||||
return d.promise;
|
||||
}
|
||||
@@ -150,8 +149,8 @@ function cleanFolder(root) {
|
||||
ignoreFiles: [],
|
||||
ignoreRules: [
|
||||
// Skip Git and SVN stuff
|
||||
".git/",
|
||||
".svn/"
|
||||
'.git/',
|
||||
'.svn/'
|
||||
]
|
||||
})
|
||||
.then(function(files) {
|
||||
|
||||
@@ -20,6 +20,10 @@ describe('eBook generator', function () {
|
||||
book.should.have.file('gitbook');
|
||||
book.should.have.file('gitbook/ebook.css');
|
||||
});
|
||||
|
||||
it('should not copy website assets', function() {
|
||||
book.should.not.have.file('gitbook/style.css');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Custom styles', function() {
|
||||
|
||||
+5
-1
@@ -16,7 +16,11 @@ describe('Website generator', function () {
|
||||
it('should correctly copy assets', function() {
|
||||
book.should.have.file('gitbook');
|
||||
book.should.have.file('gitbook/app.js');
|
||||
book.should.have.file('gitbook/website.css');
|
||||
book.should.have.file('gitbook/style.css');
|
||||
});
|
||||
|
||||
it('should not copy ebook assets', function() {
|
||||
book.should.not.have.file('gitbook/ebook.css');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Before Width: | Height: | Size: 248 KiB After Width: | Height: | Size: 248 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@@ -62,7 +62,7 @@ require(["gitbook"], function(gitbook) {
|
||||
{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
<link rel="stylesheet" href="{{ staticBase }}/website.css">
|
||||
<link rel="stylesheet" href="{{ staticBase }}/style.css">
|
||||
{% for resource in plugins.resources.css %}
|
||||
{% if resource.url %}
|
||||
<link rel="stylesheet" href="{{ resource.url }}">
|
||||
|
||||
Reference in New Issue
Block a user