- 修改文件: ruby-2.1.7-x64-mingw32\lib\ruby\2.1.0\uri\common.rb
- 修改: 在 escape 方法中 添加 us.encode!(“utf-8”)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | def escape(str, unsafe = @regexp[:UNSAFE])
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
end
str.gsub(unsafe) do
us = $&
tmp = ''
### ### fix chinese folder name becomes illegible in jekyll 2017-07-13
us.encode!("utf-8")
### ###
us.each_byte do |uc|
tmp << sprintf('%%%02X', uc)
end
tmp
end.force_encoding(Encoding::US_ASCII)
end |
webrick\httpservlet\filehandler.rb 的 prevent_directory_traversal 函数中
1
2
3
4
5
6
7 | ### ### wi-start @ 2017-07-17
# delete below
#path = req.path_info.dup.force_encoding(Encoding.find("filesystem"))
# add this
# this cause illegible characters in path, files in chinese folder 404
path = req.path_info.dup.force_encoding("utf-8").encode("gbk")
### ### @ 2017-07-17 |
1
2
3
4
5
6
7
8
9
10
11
12
13 | >bundle exec jekyll build
Configuration file: D:/documentation-theme-jekyll/_config.yml
Source: D:/documentation-theme-jekyll
Destination: D:/documentation-theme-jekyll/_site
Incremental build: disabled. Enable with --incremental
Generating...
You are missing a library required for Textile. Please run:
$ [sudo] gem install RedCloth
Conversion error: Jekyll::Converters::Textile encountered an error while converting 'hello.textile':
Missing dependency: RedCloth
ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
Missing dependency: RedCloth |
1
2
3
4
5
6
7
8 | > bundle list RedCloth
D:\ruby-2.1.7-x64-mingw32\lib\ruby\gems\2.1.0\gems\RedCloth-4.3.2\ext
> cd D:\ruby-2.1.7-x64-mingw32\lib\ruby\gems\2.1.0\gems\RedCloth-4.3.2\ext
> mkdir 2.1
> xcopy /E redcloth_scan\* 2.1\ |
1 | jekyll 3.5.1 | Error: Liquid error (line 77): Invalid GBK character "\xE2" on line 108 |
原因
sass 处理 “@import” 时读取文件,使用 File.read 是该方法默认使用 Windows 中文环境的 GBK 编码。
改不了内建的 File.read ,就只能改 Sass 了,例如:
- \sass-3.5.1\lib\sass\importers\filesystem.rb
- Sass::Importers::_find
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | module Sass
module Importers
class Filesystem
def _find(dir, name, options)
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
return unless full_filename && File.readable?(full_filename)
# TODO: this preserves historical behavior, but it's possible
# :filename should be either normalized to the native format
# or consistently URI-format.
full_filename = full_filename.tr("\\", "/") if Sass::Util.windows?
options[:syntax] = syntax
options[:filename] = full_filename
options[:importer] = self
### ###
# remove
#Sass::Engine.new(File.read(full_filename), options)
# add
Sass::Engine.new(File.read(full_filename, :encoding => "utf-8"), options)
### ###
end
end
end
end |
-
问题描述
drafts 草稿模式使用 liquid link tag 无法找到文件,这些文件放在 _posts 里面,无法在草稿模式找到。
-
解决方法
修改 link tag 的源码,只是警告提醒,而不中止编译。
ruby-2.3.3-x64-mingw32\lib\ruby\gems\2.3.0\gems\jekyll-3.3.1\lib\jekyll\tags\link.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | def render(context)
site = context.registers[:site]
site.each_site_file do |item|
return item.url if item.relative_path == @relative_path
# This takes care of the case for static files that have a leading /
return item.url if item.relative_path == "/#{@relative_path}"
end
# 找不到文档,只提醒,不报错而导致build中止。
# 使用 drafts 的时候可能无法找到link的文档
# 删除这一句
#raise ArgumentError, <<eos
# 添加这句话
Jekyll.logger.warn "WARNING:", <<eos
Could not find document '#{@relative_path}' in tag '#{self.class.tag_name}'.
Make sure the document exists and the path is correct.
eos
end |
1
2
3 | shell> irb
irb> require "webrick/httpservlet"
irb> WEBrick::HTTPServlet::FileHandler.instance_method(:set_filename).source_location |