Skip to content

Instantly share code, notes, and snippets.

@semanticart
Created November 28, 2008 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semanticart/30050 to your computer and use it in GitHub Desktop.
Save semanticart/30050 to your computer and use it in GitHub Desktop.
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