lib/softcover/commands/server.rb in softcover-0.5.0 vs lib/softcover/commands/server.rb in softcover-0.6.0
- old
+ new
@@ -10,22 +10,29 @@
def listen_for_changes
return if defined?(@no_listener) && @no_listener
server_pid = Process.pid
directories = ['.', 'chapters']
@listener = Listen.to(*directories)
- @listener.filter(/(\.tex|\.md|custom\.sty)$/)
+ file_pattern = markdown? ? '\.md' : '\.tex'
+ @listener.filter(/(#{file_pattern}|custom\.sty)$/)
+
@listener.change do |modified|
rebuild modified.try(:first)
Process.kill("HUP", server_pid)
end
@listener.start
end
+ def markdown?
+ !Dir.glob(path('chapters/*.md')).empty?
+ end
+
def rebuild(modified=nil)
printf modified ? "=> #{File.basename modified} changed, rebuilding... " :
'Building...'
t = Time.now
- Softcover::Builders::Html.new.build
+ builder = Softcover::Builders::Html.new
+ builder.build(preserve_tex: true)
puts "Done. (#{(Time.now - t).round(2)}s)"
rescue Softcover::BookManifest::NotFound => e
puts e.message
end