Add rake task for testing theme during development
- `bundle exec rake preview`
This commit is contained in:
parent
cd19062e63
commit
fc098cc1a3
1 changed files with 74 additions and 0 deletions
74
Rakefile
Normal file
74
Rakefile
Normal file
|
@ -0,0 +1,74 @@
|
|||
require "bundler/gem_tasks"
|
||||
require "jekyll"
|
||||
require "listen"
|
||||
|
||||
def listen_ignore_paths(base, options)
|
||||
[
|
||||
/_config\.ya?ml/,
|
||||
/_site/,
|
||||
/\.jekyll-metadata/
|
||||
]
|
||||
end
|
||||
|
||||
def listen_handler(base, options)
|
||||
site = Jekyll::Site.new(options)
|
||||
Jekyll::Command.process_site(site)
|
||||
proc do |modified, added, removed|
|
||||
t = Time.now
|
||||
c = modified + added + removed
|
||||
n = c.length
|
||||
relative_paths = c.map{ |p| Pathname.new(p).relative_path_from(base).to_s }
|
||||
print Jekyll.logger.message("Regenerating:", "#{relative_paths.join(", ")} changed... ")
|
||||
begin
|
||||
Jekyll::Command.process_site(site)
|
||||
puts "regenerated in #{Time.now - t} seconds."
|
||||
rescue => e
|
||||
puts "error:"
|
||||
Jekyll.logger.warn "Error:", e.message
|
||||
Jekyll.logger.warn "Error:", "Run jekyll build --trace for more information."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task :preview do
|
||||
base = Pathname.new('.').expand_path
|
||||
options = {
|
||||
"source" => base.join('example').to_s,
|
||||
"destination" => base.join('example/_site').to_s,
|
||||
"force_polling" => false,
|
||||
"serving" => true,
|
||||
"theme" => "minima"
|
||||
}
|
||||
|
||||
options = Jekyll.configuration(options)
|
||||
|
||||
ENV["LISTEN_GEM_DEBUGGING"] = "1"
|
||||
listener = Listen.to(
|
||||
base.join("_includes"),
|
||||
base.join("_layouts"),
|
||||
base.join("_sass"),
|
||||
options["source"],
|
||||
:ignore => listen_ignore_paths(base, options),
|
||||
:force_polling => options['force_polling'],
|
||||
&(listen_handler(base, options))
|
||||
)
|
||||
|
||||
begin
|
||||
listener.start
|
||||
Jekyll.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'"
|
||||
|
||||
unless options['serving']
|
||||
trap("INT") do
|
||||
listener.stop
|
||||
puts " Halting auto-regeneration."
|
||||
exit 0
|
||||
end
|
||||
|
||||
loop { sleep 1000 }
|
||||
end
|
||||
rescue ThreadError
|
||||
# You pressed Ctrl-C, oh my!
|
||||
end
|
||||
|
||||
Jekyll::Commands::Serve.process(options)
|
||||
end
|
Loading…
Reference in a new issue