Skip to content

Instantly share code, notes, and snippets.

@koron
Last active December 15, 2015 06:39
Show Gist options
  • Save koron/5218109 to your computer and use it in GitHub Desktop.
Save koron/5218109 to your computer and use it in GitHub Desktop.
手元のJekyllの修正 * DNSの逆引き禁止 * encoding指定の追加 * バイナリモードでの出力 * 生成所要時間の出力
diff --git a/bin/jekyll b/bin/jekyll
index 74cb99b..1f87449 100644
--- a/bin/jekyll
+++ b/bin/jekyll
@@ -250,7 +250,9 @@ if options['auto']
dw.add_observer do |*args|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
puts "[#{t}] regeneration: #{args.size} files changed"
- site.process
+ t = Time.now
+ num = site.process
+ puts "Built #{num} pages in #{Time.now - t} secs"
end
dw.start
@@ -261,7 +263,9 @@ if options['auto']
else
puts "Building site: #{source} -> #{destination}"
begin
- site.process
+ t = Time.now
+ num = site.process
+ puts "Built #{num} pages in #{Time.now - t} secs"
rescue Jekyll::FatalException => e
puts
puts "ERROR: YOUR SITE COULD NOT BE BUILT:"
@@ -287,7 +291,8 @@ if options['server']
s = HTTPServer.new(
:Port => options['server_port'],
- :MimeTypes => mime_types
+ :MimeTypes => mime_types,
+ :DoNotReverseLookup => true
)
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination)
t = Thread.new {
diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb
index 1fe3487..42feb71 100644
--- a/lib/jekyll/convertible.rb
+++ b/lib/jekyll/convertible.rb
@@ -25,7 +25,7 @@ module Jekyll
#
# Returns nothing.
def read_yaml(base, name)
- self.content = File.read(File.join(base, name))
+ self.content = File.read(File.join(base, name), self.site.file_read_opts)
begin
if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb
index 82b8204..ce9fd82 100644
--- a/lib/jekyll/page.rb
+++ b/lib/jekyll/page.rb
@@ -130,7 +130,7 @@ module Jekyll
def write(dest)
path = destination(dest)
FileUtils.mkdir_p(File.dirname(path))
- File.open(path, 'w') do |f|
+ File.open(path, 'wb') do |f|
f.write(self.output)
end
end
diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb
index 3934b97..9acc621 100644
--- a/lib/jekyll/post.rb
+++ b/lib/jekyll/post.rb
@@ -213,7 +213,7 @@ module Jekyll
def write(dest)
path = destination(dest)
FileUtils.mkdir_p(File.dirname(path))
- File.open(path, 'w') do |f|
+ File.open(path, 'wb') do |f|
f.write(self.output)
end
end
diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb
index 8a78e91..945a206 100644
--- a/lib/jekyll/site.rb
+++ b/lib/jekyll/site.rb
@@ -5,7 +5,8 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :pages, :static_files,
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
- :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts
+ :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
+ :file_read_opts
attr_accessor :converters, :generators
@@ -27,6 +28,11 @@ module Jekyll
self.future = config['future']
self.limit_posts = config['limit_posts'] || nil
+ self.file_read_opts = {}
+ if config['encoding']
+ self.file_read_opts[:encoding] = Encoding.find(config['encoding'])
+ end
+
self.reset
self.setup
end
@@ -41,6 +47,7 @@ module Jekyll
self.render
self.cleanup
self.write
+ return self.posts.length + self.pages.length
end
# Reset Site details.
diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb
index e71d07f..a0e53bb 100644
--- a/lib/jekyll/tags/include.rb
+++ b/lib/jekyll/tags/include.rb
@@ -20,7 +20,7 @@ module Jekyll
Dir.chdir(includes_dir) do
choices = Dir['**/*'].reject { |x| File.symlink?(x) }
if choices.include?(@file)
- source = File.read(@file)
+ source = File.read(@file, context.registers[:site].file_read_opts)
partial = Liquid::Template.parse(source)
context.stack do
partial.render(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment