summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/models
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-06 16:29:32 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-06 16:29:32 +0200
commit1354582c4e0d61c7608965f36b3c27ee3e39dc78 (patch)
tree1f1883ffec98f762d19d6a03c7506676f19822e1 /packages/gitbook-core/src/models
parent4119917555f827b0bff256a8e34a1deef5f4b87e (diff)
downloadgitbook-1354582c4e0d61c7608965f36b3c27ee3e39dc78.zip
gitbook-1354582c4e0d61c7608965f36b3c27ee3e39dc78.tar.gz
gitbook-1354582c4e0d61c7608965f36b3c27ee3e39dc78.tar.bz2
Generate an url index for generation
Diffstat (limited to 'packages/gitbook-core/src/models')
-rw-r--r--packages/gitbook-core/src/models/File.js14
-rw-r--r--packages/gitbook-core/src/models/SummaryArticle.js35
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}