Fix: task set_root_dir now works properly and outputs rewritten configuration on success

This commit is contained in:
Brandon Mathis 2013-03-17 23:46:24 -05:00
parent 50e6a1ed04
commit 4dfdfb80c2

View File

@ -411,30 +411,37 @@ end
desc "Update configurations to support publishing to root or sub directory" desc "Update configurations to support publishing to root or sub directory"
task :set_root_dir, :dir do |t, args| task :set_root_dir, :dir do |t, args|
if args.dir path = args.dir || nil
dir = args.dir if path.nil?
else path = get_stdin("Please provide a directory: ")
dir = get_stdin("Please provide a directory: ")
end end
if dir if path
if dir == "/" if path == "/"
dir = "" path = ""
else else
dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, ''); path = "/" + path.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, '');
end end
# update personal configuration # update personal configuration
site_configs = configurator.read_configuration('site.yml') site_configs = configurator.read_config('site.yml')
site_configs[:destination] = "public#{dir}" site_configs[:destination] = "public#{path}"
site_configs[:subscribe_rss] = "#{dir}/atom.xml" root = "/#{path.sub(/^\//, '')}"
site_configs[:root] = "/#{dir.sub(/^\//, '')}" url = $1 if site_configs[:url] =~ /(https?:\/\/[^\/]+)/i
site_configs[:url] = url + path
site_configs[:subscribe_rss] = "#{path}/atom.xml"
site_configs[:root] = "#{root}"
configurator.write_config('site.yml', site_configs) configurator.write_config('site.yml', site_configs)
rm_rf configuration[:destination] rm_rf configuration[:destination]
mkdir_p site_configs[:destination] mkdir_p site_configs[:destination]
puts "\n========================================================" puts "\nYour _config/site.yml has been updated to the following"
puts "Site's root directory is now '/#{dir.sub(/^\//, '')}'" output = <<-EOF
puts "Don't forget to update your url in _config.yml"
puts "\n========================================================" url: #{url + path}
destination: public#{path}
subscribe_rss: #{path}/atom.xml
root: #{root}
EOF
puts output.yellow
end end
end end