From 4dfdfb80c2bba3245f085d9e2d7fa01f230c7573 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 17 Mar 2013 23:46:24 -0500 Subject: [PATCH] Fix: task set_root_dir now works properly and outputs rewritten configuration on success --- Rakefile | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/Rakefile b/Rakefile index c345185..826e548 100644 --- a/Rakefile +++ b/Rakefile @@ -411,30 +411,37 @@ end desc "Update configurations to support publishing to root or sub directory" task :set_root_dir, :dir do |t, args| - if args.dir - dir = args.dir - else - dir = get_stdin("Please provide a directory: ") + path = args.dir || nil + if path.nil? + path = get_stdin("Please provide a directory: ") end - if dir - if dir == "/" - dir = "" + if path + if path == "/" + path = "" else - dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, ''); + path = "/" + path.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, ''); end # update personal configuration - site_configs = configurator.read_configuration('site.yml') - site_configs[:destination] = "public#{dir}" - site_configs[:subscribe_rss] = "#{dir}/atom.xml" - site_configs[:root] = "/#{dir.sub(/^\//, '')}" + site_configs = configurator.read_config('site.yml') + site_configs[:destination] = "public#{path}" + root = "/#{path.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) rm_rf configuration[:destination] mkdir_p site_configs[:destination] - puts "\n========================================================" - puts "Site's root directory is now '/#{dir.sub(/^\//, '')}'" - puts "Don't forget to update your url in _config.yml" - puts "\n========================================================" + puts "\nYour _config/site.yml has been updated to the following" + output = <<-EOF + + url: #{url + path} + destination: public#{path} + subscribe_rss: #{path}/atom.xml + root: #{root} +EOF + puts output.yellow end end