Jekyll在读取中文目录的时间报错,不能实时的监控文件变化,一遇到变更中文文件名的markdown文件就出错。
根本原因, 在原有英文代码里,没有考虑bit asc与UTF-8数据join连接造成的出错。
出现问题呢的文件是:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/pathname.rb
解决的方法是直接修改源码:
原始代码:
def children(with_directory=true)
with_directory = false if @path == '.'
result = []
Dir.foreach(@path) {|e|
next if e == '.' || e == '..'
if with_directory
result << self.class.new(File.join(@path, e))
else
result << self.class.new(e)
end
}
result
end
修改代码,如下:
def children(with_directory=true)
with_directory = false if @path == '.'
result = []
Dir.foreach(@path) {|e|
next if e == '.' || e == '..'
if with_directory
#print e, "\n"
#print @path, "\n"
result << self.class.new(File.join(@path.force_encoding("UTF-8"), e))
else
result << self.class.new(e)
end
}
result
end
关键的地方是,是将@path变成 @path.force_encoding("UTF-8") , 这样就可以和后面的“e"的UTF-8的内容进行join字符串连接了。
这样修改问题就解决了。
网友评论