Skip to content

Instantly share code, notes, and snippets.

@russmckendrick
Last active August 29, 2015 13:55
Show Gist options
  • Save russmckendrick/8768334 to your computer and use it in GitHub Desktop.
Save russmckendrick/8768334 to your computer and use it in GitHub Desktop.
Some Jekyll Snippets

Getting just the latest post;

{% for post in site.posts offset: 0 limit: 1 %}
<div class="some-style">
<a href="{{post.url}}">
<h3 class='news-title'>{{ post.title }}</h3>
<span class='news-date'>{{ post.date | date_to_string }}</span>
</a>
<p>{{ page.excerpt }} <a href='{{post.url}}'><span class='read-more'> Read more</span></a></p>
</div>
{% endfor %}

Getting the rest of the posts;

{% for post in site.posts offset: 1 limit: 4 %}
<div class="some-other-style">
<a href="{{post.url}}">
<h3 class='news-title'>{{ post.title }}</h3>
<span class='news-date'>{{ post.date | date_to_string }}</span>
</a>
<p>{{ page.excerpt }} <a href='{{post.url}}'><span class='read-more'> Read more</span></a></p>
</div>
{% endfor %}

that worked apart from I need more consistancy with the page.excerpt to keep things a little more uniform, the following code fitted the bill nicely;

{{ post.content | strip_html | truncatewords:75 }}

it even added ... to the end automagically.

gem install jekyll
jekyll new my-website
cd my-website
jekyll -w serve

You should now be able to view my-website at http://localhost:4000/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment