summaryrefslogtreecommitdiffstats
path: root/lib/utils
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-22 17:45:12 +0200
committerSamy Pessé <samypesse@gmail.com>2014-04-22 17:45:12 +0200
commit305f2210773c6f6e798d2443a28de95cc8b7bfb2 (patch)
tree632921a4696471b112eda54f6050091e3bbc09f6 /lib/utils
parent53514f2602029d61106e1214790fddf072bf9a81 (diff)
downloadgitbook-305f2210773c6f6e798d2443a28de95cc8b7bfb2.zip
gitbook-305f2210773c6f6e798d2443a28de95cc8b7bfb2.tar.gz
gitbook-305f2210773c6f6e798d2443a28de95cc8b7bfb2.tar.bz2
Fix #136: replace links to .md by links to .html
Add more tests for links in page
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/index.js1
-rw-r--r--lib/utils/links.js29
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/utils/index.js b/lib/utils/index.js
index 155e723..dbc4087 100644
--- a/lib/utils/index.js
+++ b/lib/utils/index.js
@@ -1,3 +1,4 @@
module.exports = {
lang: require('./lang'),
+ links: require('./links')
};
diff --git a/lib/utils/links.js b/lib/utils/links.js
new file mode 100644
index 0000000..2501044
--- /dev/null
+++ b/lib/utils/links.js
@@ -0,0 +1,29 @@
+var url = require('url');
+var path = require('path');
+
+// Return true if the link is relative
+var isRelative = function(href) {
+ var parsed = url.parse(href);
+
+ return !parsed.protocol && parsed.path && parsed.path[0] != '/';
+};
+
+// Relative to absolute path
+// dir: directory parent of the file currently in rendering process
+// outdir: directory parent from the html output
+
+var toAbsolute = function(_href, dir, outdir) {
+ // Absolute file in source
+ _href = path.join(dir, _href);
+
+ // make it relative to output
+ _href = path.relative(outdir, _href);
+
+ return _href;
+};
+
+
+module.exports = {
+ isRelative: isRelative,
+ toAbsolute: toAbsolute
+}; \ No newline at end of file