I have started developing static sites with Jekyll in May. For those who don’t know what it is:
Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through a converter (like Markdown) and Liquid renderer, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server.
I like the idea of modular website project that eventually will be generated into a static website. Furthermore GitHub Pages can generate and host it for you, so you get free, reliable hosting with push to deploy feature.
That’s why it was the perfect choice for Project Zeppelin - free conference site template (mostly for GDG DevFest, but for sure you can use it as you want). Unfortunately, GitHub Pages has limited number of available plug-ins, for instance, there are no plugins to compile Compass files, minify css, js and html files or highlight your code.
Fortunately, Grunt helps us with it and gives even more. So let’s get started.
Installation
First of all you need to install Bundler for easy gem dependency management.
Requirements: Install Ruby & RubyGems
Add these gems to your Gemfile:
Run this command to install them:
And don’t forget to install Grunt:
Requirements: Install Node.js
We are almost ready to use Grunt, but before that you need to create package.json, which is used by npm and contains project dependencies.
You can update dependencies with amazing tool. Simply install npm install -g npm-check-updates
and run it with npm-check-updates -u
. This command will update all dependencies to the latest versions.
To install them just run:
Grunt task configuration
Grunt allows us to define a couple of tasks and run them from the shell. They are defined in a Gruntfile.js. I’ve generated initial Gruntfile with Yeoman Generator and edited it to get better results. Here is what I’ve got.
I have used require(‘jit-grunt’)(grunt); to run tasks instead of require(‘load-grunt-tasks’)(grunt); because it much faster (6 ms compared to 4,7 s).
In the project, I compile .scss
files with grunt-sass, which uses libsass which is a Sass compiler written in C++, in purpose of performance. But there are missing features. So if you need more stable compiler or Compass support use grunt-contrib-sass.
Running grunt serve
(you can run it as default task grunt
) on the command line will perform the following tasks:
- make Jekyll magic and compile your site to
.jekyll
folder; - compile
.scss
files and autoprefix them; - compile
.js
files; - start a web server for you;
- watch your files and run Grunt tasks when they are needed.
When you are ready to deploy it on a server (in my case GitHub) run grunt deploy
, which will do the following tasks:
- make Jekyll magic and compile your site to
.jekyll
folder; - compress all images in
img
folder; - compile
.sass
files, delete unnecessary css styles, autoprefix and compress them; - compile and compress
.js
files; - generate and insert critical css into pages;
- compress
.html
pages; - push changes into gh-pages branch of git@github.com:user/repo.git remote.
Final project structure looks like:
Feel free to use my template to start developing much faster.
That’s all. Now you can easily develop your site/blog with Jekyll and get highly optimized production version of it. If you have any questions or suggestions feel free to comment here or send me a message directly.
Share with: Google+ • Twitter • Facebook