Skip to content

Instantly share code, notes, and snippets.

@tylerpearson
Last active December 17, 2015 22:08
Show Gist options
  • Save tylerpearson/5679305 to your computer and use it in GitHub Desktop.
Save tylerpearson/5679305 to your computer and use it in GitHub Desktop.
generate a wrapper file

Quick steps to generate a wrapper file from a Hifi site

  1. Make sure you have wget installed on your machine. With Homebrew use brew install wget.
  2. Put wrapper.rb in the directory where you want the files to be saved.
  3. Run the script: ruby wrapper.rb http://www.newmediacampaigns.com/about. The first and only argument is the url for an interior page that should be used as the template for the wrapper. A home page could be used, but it's unlikely you'd want that for a wrapper. The url should look something like http://www.kevinstrouse.com/about.
  4. Manually change the title, and change or remove any extra headers or content.

This should work with sites using an SSL because the assets should all be saved in the wrapper template directory.

require 'fileutils'
url = ARGV.at(0).sub(/^https?\:\/\//, '')
domain = url.slice(0..(url.index('/')))
puts "URL: #{url}"
puts "Domain: #{domain}"
if ARGV.length == 0
puts "Please add in the url as the first argument."
else
puts "Bulding a wrapper from the Hifi site http://#{domain}...\n\n"
# download the site and assets
output = `wget -E -H -k -K -p http://#{url}`
# move directories into the sample folder as the index file
Dir.foreach(".") do |file|
if File.directory? file
if file == '.' or file == '..' or file == domain.gsub("/", "")
next
else
puts "Moving: #{file}"
FileUtils.mv(file, domain + "/")
end
end
end
# fix urls to reflect the moved directories
Dir.glob("#{domain}/*.html").each do|file_name|
puts "Changing file urls"
text = File.read(file_name)
replace = text.gsub!("../", "")
File.open(file_name, "w") { |file| file.puts replace }
end
# delete the orig files
# seems like removing the -k -K flags with wget should eliminate
# the need to do this, but I can't get it to work right after removing
Dir.glob("**/*.orig").each do|file_name|
File.delete(file_name) if File.file? file_name
end
puts "Finished. Thank you, come again.\n\n"
puts "***Don't forget to manually change the titles and remove text from the content area.***\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment