Added prompt for overwriting posts and pages when a new_post and new_page tasks are run and the file already exists. Fixes #130
This commit is contained in:
parent
724fd1dbc8
commit
3f07677276
10
Rakefile
10
Rakefile
@ -92,6 +92,11 @@ task :new_post, :title do |t, args|
|
|||||||
args.with_defaults(:title => 'new-post')
|
args.with_defaults(:title => 'new-post')
|
||||||
title = args.title
|
title = args.title
|
||||||
filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
|
filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
|
||||||
|
if File.exist?(filename)
|
||||||
|
puts "### #{filename} Already exists. Overwrite? y/n:"
|
||||||
|
response = $stdin.gets.chomp.downcase
|
||||||
|
next unless response == 'y'
|
||||||
|
end
|
||||||
puts "Creating new post: #{filename}"
|
puts "Creating new post: #{filename}"
|
||||||
open(filename, 'w') do |post|
|
open(filename, 'w') do |post|
|
||||||
system "mkdir -p #{source_dir}/#{posts_dir}/";
|
system "mkdir -p #{source_dir}/#{posts_dir}/";
|
||||||
@ -119,6 +124,11 @@ task :new_page, :filename do |t, args|
|
|||||||
filename = "#{name}.#{extension}"
|
filename = "#{name}.#{extension}"
|
||||||
mkdir_p page_dir
|
mkdir_p page_dir
|
||||||
file = page_dir + filename
|
file = page_dir + filename
|
||||||
|
if File.exist?(file)
|
||||||
|
puts "### #{file} Already exists. Overwrite? y/n:"
|
||||||
|
response = $stdin.gets.chomp.downcase
|
||||||
|
next unless response == 'y'
|
||||||
|
end
|
||||||
puts "Creating new page: #{file}"
|
puts "Creating new page: #{file}"
|
||||||
open(file, 'w') do |page|
|
open(file, 'w') do |page|
|
||||||
page.puts "---"
|
page.puts "---"
|
||||||
|
Loading…
Reference in New Issue
Block a user