Multiple Blogs In Single Jekyll Website
Asked Answered
A

6

17

Is there a way I can have a single Jekyll website have more than one blog? I currently want to have two blogs in one site.

Armbrecht answered 28/1, 2013 at 11:8 Comment(2)
It seems like Google can help here: have you tried any solutions? Take a look here: garron.me/blog/multi-blog-site-jekyll.htmlHebrews
I have already looked at it. It does help but I wanted a way to implement many more blogging features like archives,displaying latest post etc. Thanks newaysArmbrecht
E
30

I am the author of the page http://www.garron.me/blog/multi-blog-site-jekyll.html

Considering that you need individual archives pages, and latest post per individual blog. Just use something like this:

Create a file archives-blog-1.html and fill it with:

{% 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>
  {% endif %}
{% endfor %}

That will give you a list of all post in blog1, you can do the same for blog2. That page can be anyplace you want.

For the latest post, you can use the same code but enclosed between:

{% for post in site.posts limit:5 %}
....
{% endfor %}

That will give you the lastes 5 posts... I am using this

{% for post in site.posts limit:5 %}

  <div class="post">
    <ul>
      <li><a href="{{ post.url }}">{{ post.title | truncate:200 }} </a><small>{{ post.date }}</small>
         {% if post.summary %}
            <p class="entry">{{ post.summary }}</p>
         {% endif %}
      </li>
    </ul>
  </div>
{% endfor %}

In my index page. http://www.garron.me/index.html ... under the sub-title (From the blogs) I am not limiting to any category, so posts from all blogs appear there, you can limit with {% if post.categories contains 'blog1' %}

Hope it helps you.

Elysha answered 29/1, 2013 at 12:51 Comment(0)
F
16

There's a simpler solution than any of the answers so far.

Folder structure:

- blog1/ - _posts/ - blog2/ - _posts/

Then in the index.html for blog1, use site.categories.blog1 instead of site.posts.

See the documentation for "site.categories" and "page.categories" in https://jekyllrb.com/docs/variables/

Finance answered 13/2, 2017 at 3:20 Comment(0)
H
1

I used two separate Jekyll installations to run two blogs on the same domain; if your blogs are going to live in separate root dirs (mine are at / and /photos/), then I'd recommend this approach. I also described how I merged both blogs' sitemap.xml files.

Homesteader answered 16/2, 2013 at 19:11 Comment(0)
W
0

Your best bet would be to look into the data files feature. You can put .markdown files in a separate folder in your source and link to them as you post. This does mean that in order to make a post, you'll need to write a data file entry, but you can host as many "blogs" as you'd like, each with their own folder. Posts will automatically have the folder they're in as the url. I use this method for my own personal blog and portfolio.

Either that, or you may want to look into collections: http://jekyllrb.com/docs/collections/

Witting answered 18/3, 2016 at 21:28 Comment(0)
B
0

Adding to @ggarron's answer, there's a short version of filtering by categories:

{% assign filtered_posts = site.posts | where_exp: "post", "post.categories contains 'blog1'" %}

The advantage of assigning to a variable is that one can replace all uses of site.posts with filtered_posts and keep consistency. For example, I have a snippet to get the first post of the list:

{% assign first_post = filtered_posts | first %}

This works as expected.

Benedetta answered 21/2, 2023 at 18:17 Comment(0)
H
0

Let's imagine that we want to separate posts into two blogs: blog1 and blog2.

All posts can be stored in one directory (although they can be placed in different directories, as suggested by @David Röthlisberger, but in fact, it doesn't matter. See jekyll's docs). To distinguish which post should go into which blog, we use the category attribute at the beginning of the .md file with the post text.

Next, we need to create files blog1.html and blog2.html in the _layouts directory. In each of them, we need to replace site.posts with site.categories.blog1 and site.categories.blog2 respectively (also, if necessary, you can replace site.posts in _layouts/home.html so that only the necessary posts are displayed on the home page, not all of them).

The last thing left to do is to create files blog1.md and blog2.md with the following content (to create links in the header):

---
layout: blog1
title: blog1
permalink: /blog1/
---
Headrace answered 4/4 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.