diff options
Diffstat (limited to 'packages/gitbook-core/src/models')
-rw-r--r-- | packages/gitbook-core/src/models/File.js | 14 | ||||
-rw-r--r-- | packages/gitbook-core/src/models/SummaryArticle.js | 35 |
2 files changed, 6 insertions, 43 deletions
diff --git a/packages/gitbook-core/src/models/File.js b/packages/gitbook-core/src/models/File.js index 03032a1..88138c3 100644 --- a/packages/gitbook-core/src/models/File.js +++ b/packages/gitbook-core/src/models/File.js @@ -21,16 +21,14 @@ class File extends Record(DEFAULTS) { } /** - * Return url for a file in a GitBook context. - * @param {Context} context - * @return {String} url + * Returns the relative path from this file to "to" + * @param {String} to + * @return {String} */ - toURL(context) { - const { file } = context.getState(); - + relative(to) { return path.relative( - path.dirname(file.path), - this.path + path.dirname(this.path), + to ); } diff --git a/packages/gitbook-core/src/models/SummaryArticle.js b/packages/gitbook-core/src/models/SummaryArticle.js index 80ef5ae..0f8ca0d 100644 --- a/packages/gitbook-core/src/models/SummaryArticle.js +++ b/packages/gitbook-core/src/models/SummaryArticle.js @@ -1,9 +1,4 @@ -const url = require('url'); -const path = require('path'); const { Record, List } = require('immutable'); -const File = require('./File'); - -const OUTPUT_EXTENSION = '.html'; const DEFAULTS = { title: '', @@ -24,36 +19,6 @@ class SummaryArticle extends Record(DEFAULTS) { } /** - * Return url for a file in a GitBook context. - * @param {Context} context - * @return {String} url - */ - toURL(context) { - const { readme } = context.getState(); - const fileReadme = readme.file; - const parts = url.parse(this.ref); - - if (parts.protocol) { - return this.ref; - } - - const file = new File(parts.pathname); - let filePath = file.toURL(context); - - // Change extension and resolve to .html - if ( - path.basename(filePath, path.extname(filePath)) == 'README' || - (fileReadme && filePath == fileReadme.path) - ) { - filePath = path.join(path.dirname(filePath), 'index' + OUTPUT_EXTENSION); - } else { - filePath = path.basename(filePath, path.extname(filePath)) + OUTPUT_EXTENSION; - } - - return filePath + (parts.hash || ''); - } - - /** * Return true if article is an instance of SummaryArticle * @param {Mixed} article * @return {Boolean} |