diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-22 10:36:28 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-22 10:36:28 +0100 |
commit | 1e243281c7f0444162dfb8593e9fd9ac2aa725ab (patch) | |
tree | d573af3258a36702ce7524f0a2143a07dece2d4e /lib/plugins | |
parent | de234944090dcb2356db1185e3fba7935dc6ee11 (diff) | |
download | gitbook-1e243281c7f0444162dfb8593e9fd9ac2aa725ab.zip gitbook-1e243281c7f0444162dfb8593e9fd9ac2aa725ab.tar.gz gitbook-1e243281c7f0444162dfb8593e9fd9ac2aa725ab.tar.bz2 |
Add test for resources listing
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/plugin.js | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js index df79184..0d69cd9 100644 --- a/lib/plugins/plugin.js +++ b/lib/plugins/plugin.js @@ -1,5 +1,6 @@ var _ = require('lodash'); var path = require('path'); +var url = require('url'); var resolve = require('resolve'); var mergeDefaults = require('merge-defaults'); var jsonschema = require('jsonschema'); @@ -191,10 +192,10 @@ BookPlugin.prototype.hook = function(name, input) { // Return resources without normalization BookPlugin.prototype._getResources = function(base) { base = base; - var book = this.infos[base]; + var book = this.content[base]; // Compatibility with version 1.x.x - if (base == 'website') book = book || this.infos.book; + if (base == 'website') book = book || this.content.book; // Nothing specified, fallback to default if (!book) { @@ -211,6 +212,25 @@ BookPlugin.prototype._getResources = function(base) { return Promise(_.cloneDeep(book)); }; +// Normalize a specific resource +BookPlugin.prototype.normalizeResource = function(resource) { + // Parse the resource path + var parsed = url.parse(resource); + + // This is a remote resource + // so we will simply link to using it's URL + if (parsed.protocol) { + return { + 'url': resource + }; + } + + // This will be copied over from disk + // and shipped with the book's build + return { 'path': this.npmId+'/'+resource }; +}; + + // Normalize resources and return them BookPlugin.prototype.getResources = function(base) { var that = this; @@ -219,7 +239,7 @@ BookPlugin.prototype.getResources = function(base) { .then(function(resources) { _.each(RESOURCES, function(resourceType) { - resources[resourceType] = (resources[resourceType] || []).map(that.normalizeResource); + resources[resourceType] = _.map(resources[resourceType] || [], that.normalizeResource); }); return resources; |