Last Updated: February 25, 2016
·
978
· ofcapl

safe and sound faster blog commits on nanoc

Introducing nanoc

I've tested various blogging platforms - from wordpress, throught blogger, tumblr or even custom CMS written by myself in Rails - none of them satisfied me.

I decided to switch to nanoc - a static page builder, developed in awesome language called Ruby.

Most of the tasks - which can sound scary for a regular blogger - I'm doing at system console or text/code editor. Custmizing template, making new subpages, writing blog posts, adding new projects - all that stuff can be done efficiently without using mouse - just take some time to get used to it.

My page is hosted by github - an awesome hosting service where I can push every change I made in matter of seconds.

Normally, to commit new changes(e.g. publish new blog post) here's my action plan:

nanoc compile
git add .
git commit -am 'new blog post added'
git push origin source
cd output
git add .
git commit -am 'new blog post added'
git push origin master
cd ..
nanoc aco

To be safe, I'm always pushing changes from development part of the site into branch source before I push something online (master branch) - to know more about dividing nanoc website, check schmurfy's awesome post about it.

But sometimes I need to commit and push couple site updates, one after another (e.g. when I'm in a hurry and I found that previous commit had some bugs) so I've decided do add shortcut functions to my system, which will speed up my workflow a bit.

So here's the thing - at the beginning, launch terminal and edit Your .bash_profile file:

open -e ~/.bash_profile

Next, we add (just copy-paste it at the bottom of the opened file) two functions: first which will push our commit to source branch and second for master one:

function cmit1()
{
  nanoc compile;
  git add .;
  git commit -am $1;
  git push origin source;
  echo 'new version deployed to source branch!';
}

In addition, second function will move us to proper folders automatically and after pushing commit it will run nanoc autocompile method:

function cmit2()
{
  cd output;
  git add .;
  git commit -am $1;
  git push origin master;
  cd ..;
  echo 'new version deployed to master branch! now starting nanoc locally..';
  nanoc aco;
}

Now You can save Your changes (cmd + s) and exit editor (cmd + q). Finally, reload .bash_profile file in the system by using command:

source ~/.bash_profile

And that's it! You can now easily and fast commit & push Your changes - go to the nanoc main folder and try them:

cmit1 'new first awesome commit'
cmit2 'new first awesome commit'

Enjoy!

--ofca