Skip to content
Jabran Rafique

WordPress to Github with Jekyll, SASS and Grunt.js

3 minutes read

Back to the 90s, then? Sort of. I've moved from WordPress to GitHub Pages, so the site is no longer generated by a content management system (CMS). It's just static HTML pages. The good news is that the workflow is a lot better than in the days of FrontPage and Dreamweaver.

WordPress is a great platform and CMS, but for a simple blog and portfolio it's more than anyone needs. What really excited me about the move was the chance to learn new tools: Jekyll, Sass, Grunt.js, Bower and CoffeeScript1, to name a few. That's a lot for one project, so I spread them across a couple of projects to learn each one properly.

The best way to learn a tool is to use it, so I started by rewriting Socialmedia.js with CoffeeScript and Grunt.js. CoffeeScript lets you write JavaScript faster, partly because you stop worrying about braces and semicolons, though it can do a lot more than that.

Grunt.js is a task runner. Everything you do in your workflow is a task: merging files, converting them, compressing them, renaming them. Grunt does those for you instead of you doing each one by hand. Once the tasks were set up I stopped alt+tabbing between windows and could focus on the code. These are the tasks I used:

  • grunt-contrib-coffee
  • grunt-contrib-concat
  • grunt-contrib-uglify
  • grunt-contrib-watch

I enjoyed those few days so much that I couldn't wait to learn the rest. After releasing Socialmedia 1.4.1, I rebuilt and simplified this website with Jekyll, Sass and Twitter Bootstrap (TWBS)2, with Grunt.js automating the tasks.

I wanted TWBS for the reset, the grid and some other styling, but I didn't want to load all of it. I could have built a custom bundle in the TWBS Customize section, but then every time I wanted to change it I'd have to remember every option I'd picked. That's no good for a workflow.

Bower and TWBS Sass solved it. I installed TWBS Sass into the project with Bower:

  $ bower install bootstrap-sass-official

Then I imported /bootstrap.scss into the site's own Sass file. Now I can comment out the parts of TWBS I don't want so they stay out of the final CSS, set my own values for the TWBS Sass variables, and use its mixins too.

Grunt.js compiles TWBS Sass and my own Sass into one CSS file and minifies it. The CSS is smaller and the page makes fewer HTTP requests. I also use the imagemin task to compress the site's images. The full list5 of tasks in this project's Gruntfile.js:

  • grunt-contrib-concat
  • grunt-contrib-uglify
  • grunt-contrib-imagemin
  • grunt-contrib-sass
  • grunt-contrib-watch

The projects section is generated from Jekyll Front Matter. I thought about pulling in my GitHub feed but dropped the idea to keep the site more personal. Each project's status and version is colour coded so you can see where it stands. The site is built mobile first3 and is fully responsive. The frontend starts from plain CSS, enhances progressively and degrades gracefully4 where it needs to. The source is on GitHub under the MIT License.

Moving from a full CMS to a site generator (Jekyll) with a task runner (Grunt.js) was brilliant. I'd recommend trying these tools to speed up your own workflow. For a quick start with Grunt.js, read Chris Coyier's article on it on 24ways.

...and welcome to my new website!

References

  1. Jekyll, Sass, Grunt.js, Bower, CoffeeScript
  2. Twitter Bootstrap
  3. Mobile First Responsive Web Design - Brad Frost
  4. Progressive Enhancement & Graceful Degradation
  5. Grunt.js plugins