11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://eleventy-base-blog.netlify.app/
MIT License
1.21k stars 619 forks source link

Show latest post on home page #78

Closed ultraloveninja closed 3 years ago

ultraloveninja commented 3 years ago

I'm messing around with setting this, but I'm wondering, what is the setting to show the latest post on the home page?

I'm not sure if I'm missing something or if there's another resource to do that?

zachleat commented 3 years ago

Do you mean the full text of the most recent post?

zachleat commented 3 years ago

Adding this to index.njk should do it:

{% for post in postslist | head(-1) %}
  <h1>{{ post.data.title }}</h1>
  {{ post.templateContent | safe }}
{% endfor %}
ultraloveninja commented 3 years ago

Adding this to index.njk should do it:

{% for post in postslist | head(-1) %}
  <h1>{{ post.data.title }}</h1>
  {{ post.templateContent | safe }}
{% endfor %}

Interesting. I tried that and it comes back with a slice error:

TypeError: Cannot read property 'slice' of undefined

ultraloveninja commented 3 years ago

Ok so using this ended up working:

{% set postslist = collections.posts | head(-1) %}

{% for post in postslist | head(-1) %}
  <h1>{{ post.data.title }}</h1>
  {{ post.templateContent | safe }}
{% endfor %}