The long way through Software Craftsmanship

Faster site generation with a native Octopress 2

Apr 17, 2016 - 2 minute read - Comments - metaoctopress-2octopressnative-octopressrakefilereinventing-the-wheel

Note: this article is an answer to a previous one, about the same topic: a tool for a faster site generation while developing / writing articles, using octopress 2.

Introduction

Octopress 2 packs, out of the box, some tasks to speed up the site generation while you’re writing articles:

Isolate a post:

# 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|
  stash_dir = "#{source_dir}/#{stash_dir}"
  FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
  Dir.glob("#{source_dir}/#{posts_dir}/*.*") do |post|
    system "git update-index --assume-unchanged #{post}" unless post.include?(args.filename)
    FileUtils.mv post, stash_dir unless post.include?(args.filename)
  end
end

Integrate with the rest of the posts:

desc "Move all stashed posts back into the posts directory, ready for site generation."
task :integrate do
  posts_dir = "#{source_dir}/#{posts_dir}/"
  Dir.glob("#{source_dir}/#{stash_dir}/*.*") do |post|
    FileUtils.mv post, posts_dir
    full_path = "#{posts_dir}/#{post.split("/").reverse.first}"
    system "git update-index --no-assume-unchanged #{full_path}"
  end
end

Usage

(at the folder where the Rakefile is located)

  • isolate the selected file. Specify the pattern to keep.
rake isolate["draft"]
  • write the new content
  • commit to git
  • integrate with the rest of the files
rake integrate
  • git push

Conclusion

When I needed this tool, to speed up my feedback cycle, I didn’t find any that did this job, so I created a small tool for this same purpose. Unfortunately, there was one, so close to my nose that I could not find it. I was reinventing the wheel.

It is better to switch to a tool that has been tested by more users, that has received the community’s approval than a custom-made tool.

Self-Study in April 2016 Brownish Greenfield Gilded Rose Kata