Multi-site setup using Jekyll

Continuing on my previous post about my Jekyll setup. As I noted, I use Jekyll to publish two sites which have many things in common. After some messing around, I’m finally happy with the organization and usage of this setup.

The two site share the following things:

  • assets
  • includes
  • plugins
  • layouts

Tasks in my fabfile are adapted to multi-site usage and I also have tasks to generate the configuration files.

The organization of the files is as follow:

sites/
  _assets/
  _includes/
  _plugins/
  _layouts/
  maximebf.com/
  travelingcoder.com/
  crontab
  fabfile.py
  nginx.conf
  supervisor.conf

_assets, _includes, _plugins and _layouts are shared by all sites.

I have created three plugins to add support for more than one _layouts and _includes folder as well as copying the shared assets over to each sites.

I made a Gist containing all files from this post. Here are the three plugins:

(Note that they’re not very flexible and were made for my own use case)

I also created a config_files.rb plugin which will scan your site folder for any .config.yml file and add them to the configuration. (I use this on travelingcoder.com to keep map data out of the main _config.yml file).

The _config.yml file for each of my sites look something like this:

plugins: ../_plugins
includes: 
  - ../_includes
  - _includes
layouts:
  - ../_layouts
  - _layouts
future: false

Some of the shared _includes are Disqus and Google Analytics code, the footer, the sharing widget and common assets for <head>.

The content of the _assets folder is merged with the assets folder in each site directories.

Compared to my previous post, tasks in my fabfile take a domain argument.

$ fab serve:maximebf.com
$ fab publish:all

The crontab has to be modified to use publish:all instead of publish.

The nginx.conf and supervisor.conf files are actually templates and I use a task to generate the final configuration for every domain:

$ sudo fab gen_conf # all domains
$ sudo fab gen_conf:maximebf.com # one domain

I recently added a third site to this setup and although it shares not much with the two others, it has worked out very well.



comments powered by Disqus

30/07/2013