Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all the blog posts (with content) with Jekyll

Tags:

jekyll

I'm trying to show the top 3 blog posts in Jekyll. Using Jekyll bootstrap, I see that there is a layout for a post (a layout and an underlying theme page) - what I want to do is repeat that post layout for each of the posts.. Something like:

  {% for post in site.posts %}
    -- Render the post layout for this post.
  {% endfor %}

I'm not sure how to do this without having to copy the content for the post layout, and either add it inside that for loop, or create a JB include, which still doesn't solve the problem 'cos I'll still have to copy and paste the post html markup.

like image 987
Matt Roberts Avatar asked Mar 20 '12 20:03

Matt Roberts


People also ask

Is Jekyll faster than WordPress?

Another reason for using Jekyll as your default hosting platform is that it's a lot fast than WordPress. Unlike WordPress, it won't crash when there's a lot of traffic on our website.


2 Answers

In the end, I realised that I don't need most of the markup from the post layout, so I took what I need and embedded this in the for loop..

{% for post in site.posts %}
{% include JB/post_content %}
{% endfor %}

and post_content

<article class="unit-article layout-post">
    <div class="unit-inner unit-article-inner">
        <div class="content">
            <div class="bd">
                <div class="entry-content">
                    {{ post.content }}
                </div><!-- entry-content -->
            </div><!-- bd -->
        </div><!-- content -->
    </div><!-- unit-inner -->
</article>
like image 50
Matt Roberts Avatar answered Sep 22 '22 02:09

Matt Roberts


Yup. We ended up using a similar format:

<h3>Posts</h3>
<ul>
  {% for post in site.posts %}
  <li>
    <a href="{{ post.url }}">{{ post.title }}</a>
  </li>
  {% endfor %}
</ul>
like image 28
ramijames Avatar answered Sep 26 '22 02:09

ramijames