Open gene-pavlovsky opened 8 years ago
+1, same on Windows 10 for me. In any OS URLs should always have only forward slash "/". Anyway I don't see any advantages of using custom functions when you always can type path with leading slash "/assets/css/custom.css"
@Mevrael relative paths can be useful when deploying files not in web server's root. E.g. I'm working on http://www.example.com and deploying everything in it's root, but on my work computer I'm using a local web server and since I work on more than one website, my files reside are on http://localhost/www.example.com, using relative paths it works same on both my local dev server and on the production server.
Workaround - using a custom layout, added this helpers/asset.js
:
var handlebars = require('handlebars');
module.exports = function(context, options) {
var output = '';
// data.root is the original item (e.g. the value from the stream)
// it will have an assetsRelative path from the setOutputPath function
output += options.data.root.assetsRelative + '/';
// Get rid of any leading slash on the context
context = context.replace(/^\//, '');
output += context;
return new handlebars.SafeString(output.replace(/\\/g, '/'));
};
The output.replace(...)
in the last line changes all backslashes to forward slashes.
This line in my layout template:
<link href="{{asset 'css/bootstrap.min.css'}}" rel="stylesheet">
Becomes this when generate-md is used on Windows:<link href="..\assets/css/bootstrap.min.css" rel="stylesheet">
Shouldn't URLs always use forward slash? Culprit seems to be
lib/set-output-path.js