Created
November 28, 2008 19:01
-
-
Save semanticart/30050 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
desc "Creates a static copy of your site by iterating your thingies." | |
task :make_static do | |
static_dir = File.join(File.dirname(__FILE__), 'static') | |
Dir.mkdir(static_dir) unless File.directory?(static_dir) | |
require 'sinatra' | |
Sinatra::Application.default_options.merge!( | |
:run => false, | |
:env => :production, | |
:views => File.dirname(__FILE__) + "/views" | |
) | |
require 'stuff' | |
@request = Rack::MockRequest.new(Sinatra.application) | |
# the index | |
File.open(File.join(static_dir, 'index.html'), 'w'){|f| f.print @request.request('get', '/').body} | |
# the rss | |
Dir.mkdir(File.join(static_dir, 'tidbits')) unless File.directory?(File.join(static_dir, 'tidbits')) | |
File.open(File.join(static_dir, 'tidbits', 'rss'), 'w'){|f| f.print @request.request('get', '/tidbits/rss').body} | |
# the thingies | |
ALL_THINGIES.each do |thingie| | |
Dir.mkdir(File.join(static_dir, thingie.permalink)) unless File.directory?(File.join(static_dir, thingie.permalink)) | |
File.open(File.join(static_dir, thingie.permalink, 'index.html'), 'w'){|f| f.print @request.request('get', "/#{thingie.permalink}").body} | |
end | |
# the topics | |
Dir.mkdir(File.join(static_dir, 'topic')) unless File.directory?(File.join(static_dir, 'topic')) | |
ALL_THINGIES.map{|thing| thing.topic}.uniq.each do |topic| | |
Dir.mkdir(File.join(static_dir, 'topic', topic)) unless File.directory?(File.join(static_dir, 'topic', topic)) | |
File.open(File.join(static_dir, 'topic', topic, 'index.html'), 'w'){|f| f.print @request.request('get', "/topic/#{topic}").body} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment