单个Jekyll网站中的多个博客

时间:2013-01-28 11:08:13

标签: ruby jekyll

有没有办法让一个Jekyll网站有多个博客?我目前希望在一个网站上有两个博客。

4 个答案:

答案 0 :(得分:26)

我是页面http://www.garron.me/blog/multi-blog-site-jekyll.html

的作者

考虑到您需要个人档案页面,以及每个博客的最新帖子。只需使用这样的东西:

创建文件archives-blog-1.html并填写:

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

这将为您提供blog1中所有帖子的列表,您可以对blog2执行相同的操作。该页面可以是您想要的任何地方。

对于最新的帖子,您可以使用相同的代码,但包含在:

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

那会给你5个帖子......我正在使用这个

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

在我的索引页面中。 http://www.garron.me/index.html ...在小标题下(来自博客) 我不限于任何类别,因此所有博客的帖子都会显示在那里,您可以使用{% if post.categories contains 'blog1' %}

进行限制

希望它对你有所帮助。

答案 1 :(得分:6)

到目前为止,解决方案比任何答案都简单。

文件夹结构:

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

然后在blog.html的index.html中,使用site.categories.blog1代替site.posts

请参阅&#34; site.categories&#34;的文档。和&#34; page.categories&#34;在https://jekyllrb.com/docs/variables/

答案 2 :(得分:0)

我使用两个单独的Jekyll安装来运行two blogs on the same domain;如果你的博客将生活在单独的根目录中(我的博客位于//photos/),那么我建议采用这种方法。我也是described how I merged both blogs' sitemap.xml files

答案 3 :(得分:0)

您最好的选择是查看data files功能。您可以将s个文件放在.markdown的单独文件夹中,并在发布时链接到这些文件夹。这意味着,为了发布帖子,您需要编写一个数据文件条目,但您可以根据需要托管尽可能多的“博客”,每个博客都有自己的文件夹。帖子会自动将其所在的文件夹作为网址。我将这种方法用于我自己的个人博客和投资组合。

要么是这样,要么您可能想要查看集合:http://jekyllrb.com/docs/collections/