wintersmith-makerelative.coffee 414 B

123456789101112131415
  1. module.exports = (env, callback) ->
  2. count = (string, substr) ->
  3. num = pos = 0
  4. return 1/0 unless substr.length
  5. num++ while pos = 1 + string.indexOf(substr, pos)
  6. num
  7. env.helpers.makeRelative = (source, dest) ->
  8. return dest unless dest.indexOf("/") == 0
  9. depth = count(source, '/') # 1 being /
  10. ret = ""
  11. ret += "../" while depth = depth - 1
  12. ret + dest.substring(1)
  13. callback()