Created
April 5, 2012 09:11
-
-
Save Heliosmaster/2309393 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
# `sed -i 's/<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>/ | |
#<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n | |
# <meta http-equiv="Content-Type" content="text\/html; charset=UTF-8"\/>/g' #{filename}` | |
#out = `find . -name "*.htm*" | xargs file -i` | |
if ARGV.size > 0 | |
out = `file -i #{ARGV[0]}/*.htm*` | |
else | |
out = `file -i *.htm*` | |
end | |
out.split("\n").each do |l| | |
l =~ /(.*):(.*)charset=(.*)/ | |
filename = "#{$1}" | |
charset = "#{$3}" | |
charset = "windows-1252" if charset == "unknown-8bit" | |
if (charset!= "binary" && charset != "us-ascii" && charset != "utf-8") | |
succ = system("iconv -f #{charset} -t utf-8 #{filename} -o #{filename}") | |
if !succ | |
File.open("iconv_failed.txt", "a"){ |file| file.puts "#{filename}"} | |
puts "#{filename}" | |
end | |
#puts "#{filename} - #{charset}" | |
end | |
# if (charset!= "binary") | |
# begin | |
# text = File.read("#{filename}") | |
# already_encoded = (text =~ /<META(.*)NAME="?GENERATOR"? CONTENT="(Microsoft FrontPage|Claris Home Page)(.*)">/i) | |
# # puts "#{filename}" unless already_encoded.nil? | |
# rescue | |
# puts "@@ error with #{filename}!" | |
# end | |
# unless already_encoded.nil? | |
# #puts "#{filename} - #{text}" | |
# replace = text.gsub!(/<META(.*)NAME="?GENERATOR"? CONTENT="(Microsoft FrontPage|Claris Home Page)(.*)">/i, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>") | |
# File.open("#{filename}", "w") { |file| file.puts replace } | |
# end | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment