Create a Multi Blog Site with Jekyll

Written by
Date: 2012-04-06 22:20:00 00:00


Introduction

One of the best platforms to run a multi blog site is Drupal. You can create a lot of accounts and each one can own a blog in the site. Wordpress also have its solution, it started as Wordpress MU, but since version 3.0 that feature is embedded in the core code.

But for those of you who like to blog like a hacker, there is also way to do it.

Most of Jekyll users may already know this, I'm writing this for the newcomers.

This all started almost a year ago, when I started writing about Android in my Linux related blog, one of my readers told me.

You may blog about Android here, but just be sure all your readers do not get confused. Android is not Linux.

I then realized that I needed a multi blog site. And I created this site. I wanted it to be static pages and Nginx powered, so I had to find the way to make Jekyll create a multi blog site. Each with its own index page, and with its own RSS feed too.

Create the site structure

Usually Jekyll structure is:

|--_config.yml
|--_includes
|--_layouts
|  |--default.html
|  |--post.html
|--_posts
|  |--2012-04-06-title-of-post.md
|--_site
|--index.html
|--css
|--js

But for a multi blog site, you will create something like this:

|--_config.yml
|--_includes
|--_layouts
|  |--default.html
|  |--post.html
|--blog1
|  |--index.html
|  |--_posts
|  |  |--2012-04-06-hello-world.md
|  |--images
|--blog2
|  |--index.html
|  |--_posts
|  |--images
|--blog3
|  |--index.html
|  |--_posts
|  |--images
|--index.html
|--css
|--js

Yaml Front Matter

One thing to consider in the Yaml Front Matter is that we need to include a way to separate one blog from the other. I'm using category to do that, but you can use another variable, which may be a better idea.

Here is an example of how I do it:

---
layout: post
category: blog1
title: 'My first post'
date: 2012-04-06 21:35
---

I'm going to filter posts by category to create a different index and atom feed for each blog. So blog 2 should look like this:

---
layout: post
category: blog2
title: 'My first post'
date: 2012-04-06 21:35
---

Creating Index and Atom Feed for Each Blog

Here is an example of and index page on one blog:

---
layout: default
title: Blog1
category: blog1
---
{% raw %}
{% for post in site.posts %}
  {% if post.categories contains 'blog1' %}
	<div class="post">
		<h3 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h3>
		<p class="meta">Date: {{ post.date }}</p>
		<div class="entry">
			{{ post.content | strip_html | truncatewords: 100 }}
		</div>
	</div>
  {% endif %}
{% endfor %}
{% endraw %}

And for the atom feed:

---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title type="text" xml:lang="en">Blog 1</title>
    <link type="application/atom+xml" href="http://www.example.com/blog1/atom.xml" rel="self"/>
    <link type="text" href="http://garron.me" rel="alternate"/>
    <updated>{{ site.time | date_to_xmlschema }}</updated>
    <id>http://example.com</id>
    <author>
        <name>Guillermo Garron</name>
    </author>
    <rights>Copyright (c) 2010-2011 Guillermo Garron</rights>
    {% raw %}
    {% for post in site.posts limit:20 %}
    {% if post.categories contains 'blog1' %}
    <entry>
        <title>{{ post.title }}</title>
        <link href="http://garron.me{{ post.url }}"/>
        <updated>{{ post.date | date_to_xmlschema }}</updated>
        <id>http://garron.me{{ post.url }}</id>
        <summary type="html">{{ post.content | xml_escape }}</summary>
    </entry>
    {% endif %}
    {% endfor %}
    {% endraw %}
</feed>

Finishing the site

You can create a common index page in the root directory, that includes all posts from all blogs, or create a single page with a menu navigation for all other blogs. The same way you can include a general atom file, or just do not have one.

Multi Author Site

If the site is not only multi-blog, but also multi-writer, you may create symbolic links between blog1, blog2, etc folders, to /home/user1/public_html/ of each user.

To do

I'm not a ruby coder, so I can't do this part, but it could be great to have rake file to create posts for each users, that will include the yaml front matter, with the specific information of his blog.

You can download the structure here explained from my github repository

If you find any error, or a better way to do something, please contact using the contact page.