Multiple Blogs In Single Jekyll Website

后端 未结 4 1834
后悔当初
后悔当初 2020-12-30 05:52

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.

相关标签:
4条回答
  • 2020-12-30 06:22

    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.

    0 讨论(0)
  • 2020-12-30 06:23

    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/

    0 讨论(0)
  • 2020-12-30 06:24

    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/

    0 讨论(0)
  • 2020-12-30 06:41

    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.

    0 讨论(0)
提交回复
热议问题