Created
August 20, 2024 18:03
-
-
Save zenspider/3da71f0ad0a9cf7d92b36f3e921b4699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ZenwebBuilder < WEBrick::HTTPServlet::FileHandler | |
@@semaphore = Mutex.new | |
def service req, res | |
@@site ||= @@semaphore.synchronize { website } | |
url = req.path | |
target_path = File.join(".site", url) | |
target_path = File.join target_path, "index.html" if | |
File.directory? target_path | |
task = Rake.application[target_path] rescue nil | |
if task then | |
unless system "#{Gem.ruby} -S rake clean generate" then | |
warn "WARNING: couldn't run 'rake clean generate' properly, exited: %p" % [$?] | |
end | |
@@site = nil | |
Rake.application = Rake::Application.new # reset | |
if target_path =~ /(html|css|js)$/ then | |
task.clear_timestamp | |
task.reenable | |
end | |
else | |
warn "NOTE: No file found for %s (%s)" % [url, target_path] | |
end | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment