-
-
Save rcmdnk/27238df31e8f6b2a5c84 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
## -- Misc Configs -- ## | |
stash_dir = "_stash" # directory to stash posts for speedy generation | |
full_stash_dir = "#{source_dir}/#{stash_dir}" # full path for stash dir | |
stash_root_dir = "_stash_root" # directory to stash pages (in /source/) | |
full_stash_root_dir = "#{source_dir}/#{stash_root_dir}" # full path for stash_root dir | |
root_stashes = ['Your-Page'] # directories to be stashed in /source/ | |
# usage rake isolate[my-post] | |
desc "Move all other posts than the one currently being worked on to a temporary stash location (stash) so regenerating the site happens much more quickly." | |
task :isolate, :filename do |t, args| | |
if args.filename | |
filename = args.filename | |
else | |
filename = Dir.glob("#{source_dir}/#{posts_dir}/*.#{new_post_ext}").sort_by{|f| File.mtime(f)}.last | |
end | |
if filename == nil | |
puts "" | |
puts "There is no markdown file (*.#{new_post_ext}) in #{source_dir}/#{posts_dir}." | |
exit 1 | |
end | |
puts "## Stashing other posts than #{filename}" | |
FileUtils.mkdir(full_stash_dir) unless File.exist?(full_stash_dir) | |
Dir.glob("#{source_dir}/#{posts_dir}/*") do |post| | |
if post.include?(filename) | |
p "Remaining #{post}..." | |
else | |
FileUtils.mv post, full_stash_dir | |
end | |
end | |
FileUtils.mkdir(full_stash_root_dir) unless File.exist?(full_stash_root_dir) | |
if defined? root_stashes == nil | |
if root_stashes.class == String | |
FileUtils.mv "#{source_dir}/#{root_stashes}", full_stash_root_dir | |
elsif root_stashes.class == Array | |
for d in root_stashes do | |
FileUtils.mv "#{source_dir}/#{d}", full_stash_root_dir | |
end | |
end | |
end | |
system "touch .isolated" | |
end | |
desc "Move all stashed posts back into the posts directory, ready for site generation." | |
task :integrate do | |
FileUtils.mv Dir.glob("#{full_stash_dir}/*"), "#{source_dir}/#{posts_dir}/" | |
FileUtils.mv Dir.glob("#{full_stash_root_dir}/*"), "#{source_dir}/" | |
system "rm -f .isolated" | |
system "touch .integrated" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment