【问题标题】:Multiple Blogs In Single Jekyll Website单个 Jekyll 网站中的多个博客
【发布时间】:2013-01-28 11:08:12
【问题描述】:

有没有办法让一个 Jekyll 网站拥有多个博客?我目前想在一个站点中拥有两个博客。

【问题讨论】:

  • Google 似乎可以在这里提供帮助:您尝试过任何解决方案吗?看这里:garron.me/blog/multi-blog-site-jekyll.html
  • 我已经看过了。它确实有帮助,但我想要一种方法来实现更多博客功能,如存档、显示最新帖子等。谢谢 neways

标签: ruby jekyll


【解决方案1】:

我是页面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' %}进行限制

希望对您有所帮助。

【讨论】:

    【解决方案2】:

    到目前为止,有一个比任何答案都更简单的解决方案。

    文件夹结构:

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

    然后在 blog1 的 index.html 中,使用 site.categories.blog1 而不是 site.posts

    请参阅https://jekyllrb.com/docs/variables/ 中的“site.categories”和“page.categories”文档

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        最好的办法是研究data files 功能。您可以将.markdown 文件放在source 的单独文件夹中,并在发布时链接到它们。这确实意味着为了发表一篇文章,您需要编写一个数据文件条目,但是您可以托管任意数量的“博客”,每个博客都有自己的文件夹。帖子将自动将它们所在的文件夹作为 url。我将这种方法用于我自己的个人博客和作品集。

        要么,或者您可能想要查看集合:http://jekyllrb.com/docs/collections/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-01-25
          • 1970-01-01
          相关资源
          最近更新 更多