Skip to content

Instantly share code, notes, and snippets.

@ocxo
Created January 7, 2013 19:12
Show Gist options
  • Select an option

  • Save ocxo/4477568 to your computer and use it in GitHub Desktop.

Select an option

Save ocxo/4477568 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'iconv'
def read_dir(dir, opts={})
Dir.glob("#{dir}/*").each_with_object({}) do |f, h|
if File.file?(f)
File.open(f, "r:UTF-8") do |rf|
puts rf.path
unless File.extname(rf) == ".inc"
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
content = ic.iconv(rf.read)
content.gsub!(/<!-- CSS Stylesheet -->(.*)<title>/m, opts[:inner_header])
content.gsub!(/<div class="full-width network-bar">(.*)<div class="container body-shadow" id="forumsContainer">/m, opts[:header])
content.gsub!(/<div class="full-width footer-top">.*<\/html>/m, opts[:footer])
content.gsub!(/<br \/><div style="z-index:3" class="smallfont" align="center">Search Engine Friendly URLs by <a rel="nofollow" href="http:\/\/www.crawlability.com\/vbseo\/">vBSEO<\/a> 3.1.0<\/div>/m, "")
File.open(rf, "w:UTF-8") { |wf| wf.write(content) }
end
end
elsif File.directory?(f)
h[f] = read_dir(f, opts)
end
end
end
inner_header = <<-EOF
<!--#include virtual="/forums/inner-head.inc" -->
<title>
EOF
header = <<-EOF
<!--#include virtual="/forums/header.inc" -->
<div class="container body-shadow" id="forumsContainer">
EOF
footer = <<-EOF
<!--#include virtual="/forums/footer.inc" -->
EOF
read_dir(ARGV[0], {inner_header: inner_header, header: header, footer: footer})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment