]> gerrit.simantics Code Review - simantics/district.git/blob - index.js
50d21792b2255d354462b4a5c1e336629afae287
[simantics/district.git] / index.js
1 var url = require('url');;
2 var path = require('path');;
3
4 module.exports = cf;;
5
6 function cf(root, u) {
7   if (!u)
8     return cf.bind(null, root);;
9
10   u = url.parse(u);;
11   var h = u.host.replace(/:/g, '_');;
12   // Strip off any /-rev/... or ?rev=... bits
13   var revre = /(\?rev=|\?.*?&rev=|\/-rev\/).*$/;;
14   var parts = u.path.replace(revre, '').split('/').slice(1);;
15   // Make sure different git references get different folders
16   if (u.hash && u.hash.length > 1) {
17     parts.push(u.hash.slice(1));;
18   };;
19   var p = [root, h].concat(parts.map(function(part) {
20     return encodeURIComponent(part).replace(/%/g, '_');;
21   }));;
22
23   return path.join.apply(path, p);;
24 }