diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-22 17:45:12 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-22 17:45:12 +0200 |
commit | 305f2210773c6f6e798d2443a28de95cc8b7bfb2 (patch) | |
tree | 632921a4696471b112eda54f6050091e3bbc09f6 /lib/utils/links.js | |
parent | 53514f2602029d61106e1214790fddf072bf9a81 (diff) | |
download | gitbook-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/links.js')
-rw-r--r-- | lib/utils/links.js | 29 |
1 files changed, 29 insertions, 0 deletions
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 |