lib/jekyll/commands/serve.rb in jekyll-4.2.2 vs lib/jekyll/commands/serve.rb in jekyll-4.3.0
- old
+ new
@@ -19,15 +19,15 @@
"detach" => ["-B", "--detach",
"Run the server in the background",],
"ssl_key" => ["--ssl-key [KEY]", "X.509 (SSL) Private Key."],
"port" => ["-P", "--port [PORT]", "Port to listen on"],
"show_dir_listing" => ["--show-dir-listing",
- "Show a directory listing instead of loading" \
- " your index file.",],
+ "Show a directory listing instead of loading " \
+ "your index file.",],
"skip_initial_build" => ["skip_initial_build", "--skip-initial-build",
- "Skips the initial site build which occurs before" \
- " the server is started.",],
+ "Skips the initial site build which occurs before " \
+ "the server is started.",],
"livereload" => ["-l", "--livereload",
"Use LiveReload to automatically refresh browsers",],
"livereload_ignore" => ["--livereload-ignore ignore GLOB1[,GLOB2[,...]]",
Array,
"Files for LiveReload to ignore. " \
@@ -111,12 +111,12 @@
private
def validate_options(opts)
if opts["livereload"]
if opts["detach"]
- Jekyll.logger.warn "Warning:", "--detach and --livereload are mutually exclusive." \
- " Choosing --livereload"
+ Jekyll.logger.warn "Warning:", "--detach and --livereload are mutually exclusive. " \
+ "Choosing --livereload"
opts["detach"] = false
end
if opts["ssl_cert"] || opts["ssl_key"]
# This is not technically true. LiveReload works fine over SSL, but
# EventMachine's SSL support in Windows requires building the gem's
@@ -130,25 +130,25 @@
end
elsif %w(livereload_min_delay
livereload_max_delay
livereload_ignore
livereload_port).any? { |o| opts[o] }
- Jekyll.logger.abort_with "--livereload-min-delay, "\
- "--livereload-max-delay, --livereload-ignore, and "\
- "--livereload-port require the --livereload option."
+ Jekyll.logger.abort_with "--livereload-min-delay, --livereload-max-delay, " \
+ "--livereload-ignore, and --livereload-port require " \
+ "the --livereload option."
end
end
# rubocop:disable Metrics/AbcSize
def register_reload_hooks(opts)
require_relative "serve/live_reload_reactor"
@reload_reactor = LiveReloadReactor.new
Jekyll::Hooks.register(:site, :post_render) do |site|
- regenerator = Jekyll::Regenerator.new(site)
- @changed_pages = site.pages.select do |p|
- regenerator.regenerate?(p)
+ @changed_pages = []
+ site.each_site_file do |item|
+ @changed_pages << item if site.regenerator.regenerate?(item)
end
end
# A note on ignoring files: LiveReload errs on the side of reloading when it
# comes to the message it gets. If, for example, a page is ignored but a CSS
@@ -172,11 +172,12 @@
# rubocop:enable Metrics/AbcSize
# Do a base pre-setup of WEBRick so that everything is in place
# when we get ready to party, checking for an setting up an error page
# and making sure our destination exists.
-
+ #
+ # rubocop:disable Security/IoMethods
def setup(destination)
require_relative "serve/servlet"
FileUtils.mkdir_p(destination)
if File.exist?(File.join(destination, "404.html"))
@@ -186,16 +187,18 @@
@body = IO.read(File.join(@config[:DocumentRoot], "404.html"))
end
end
end
end
+ # rubocop:enable Security/IoMethods
def webrick_opts(opts)
opts = {
:JekyllOptions => opts,
:DoNotReverseLookup => true,
:MimeTypes => mime_types,
+ :MimeTypesCharset => mime_types_charset,
:DocumentRoot => opts["destination"],
:StartCallback => start_callback(opts["detach"]),
:StopCallback => stop_callback(opts["detach"]),
:BindAddress => opts["host"],
:Port => opts["port"],
@@ -260,12 +263,11 @@
address = server_address(server, opts)
return system "start", address if Utils::Platforms.windows?
return system "xdg-open", address if Utils::Platforms.linux?
return system "open", address if Utils::Platforms.osx?
- Jekyll.logger.error "Refusing to launch browser; " \
- "Platform launcher unknown."
+ Jekyll.logger.error "Refusing to launch browser. Platform launcher unknown."
end
# Keep in our area with a thread or detach the server as requested
# by the user. This method determines what we do based on what you
# ask us to do.
@@ -274,13 +276,12 @@
pid = Process.fork do
server.start
end
Process.detach(pid)
- Jekyll.logger.info "Server detached with pid '#{pid}'.", \
- "Run `pkill -f jekyll' or `kill -9 #{pid}'" \
- " to stop the server."
+ Jekyll.logger.info "Server detached with pid '#{pid}'.",
+ "Run `pkill -f jekyll' or `kill -9 #{pid}' to stop the server."
else
t = Thread.new { server.start }
trap("INT") { server.shutdown }
t.join
end
@@ -349,9 +350,13 @@
end
def mime_types
file = File.expand_path("../mime.types", __dir__)
WEBrick::HTTPUtils.load_mime_types(file)
+ end
+
+ def mime_types_charset
+ SafeYAML.load_file(File.expand_path("serve/mime_types_charset.json", __dir__))
end
def read_file(source_dir, file_path)
File.read(Jekyll.sanitized_path(source_dir, file_path))
end