Jekyll scss converter fails if parent folder name contains brackets
neumannm opened this issue · comments
I do not know if I just found a bug or a feature, but here's the issue:
If you have a Jekyll project in a folder website
which is below another folder containing brackets, e.g. /<somepath>/[my]websites/website
, Jekyll's scss converter cannot seem to find referenced files to import. For example here's the error message I get:
Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/main.scss': File to import not found or unreadable: imports/functions. on line 19
If I rename the parent folder to something without brackets, it works again.
Note that I am talking about the parent folder of the project, not the name of the project folder itself. So I don't know why Jekyll or the conversion script would even care about this, but maybe it takes the whole path into account and then stumbles on the brackets (though I did not know of any rule that you cannot have brackets in path names).
Hi @neumannm, will you be able to open a sample repository on GitHub that I can clone at my end to reproduce this..?
Hi @ashmaroli, sure you can clone my test repo from https://github.com/neumannm/curious-strawberry
Thanks @neumannm I was able reproduce the reported issue. I'll get back to you regarding whether this can be fixed at our end or if there's a workaround otherwise..
@neumannm Since this issue revolves around the parent directory, you may easily circumvent this by renaming the directory.
Workaround
In the event the above is not practical, have the following Ruby code as a plugin in your _plugins
directory.
# frozen_string_literal: true
module Jekyll
module Converters
class Scss < Converter
def sass_load_paths
paths = user_sass_load_paths + [sass_dir_relative_to_site_source]
if safe?
# Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
paths.map! { |path| Jekyll.sanitized_path(site_source, path) }
end
Dir.chdir(site_source) do
paths = paths.flatten.uniq
paths.map! do |path|
if safe?
Jekyll.sanitized_path(site_source, path)
else
File.expand_path(path)
end
end
end
paths.select { |path| File.directory?(path) }
end
end
end
end
For others stumbling upon this ticket, do note that the workaround plugin above is not advised if you have configured additional sass-load-paths with glob patterns in your config file.
Thanks @ashmaroli - for me, renaming the parent directory was fine. I just thought you should know about this issue since, as I said, I think the converting script shouldn't be affected by higher-level directory names.