Skip to content

Commit

Permalink
move category index into layout:
Browse files Browse the repository at this point in the history
- makes it easier for someone to setup a post category index as they’ll
just need to create make a page and specify the front matter
  • Loading branch information
broccolini committed Sep 17, 2016
1 parent caae950 commit c37680a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
17 changes: 17 additions & 0 deletions _layouts/category_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
layout: page
---

{% if page.category_name %}
{% assign category_name = page.category_name %}
{% endif %}

{% for post in site.categories[category_name] %}
<div class="container mx-auto py-2 mb-2 prose">
<a class="no-underline h5 bold text-accent" title="{{ post.url | prepend: site.baseurl }}" href="{{ post.url | prepend: site.baseurl }}">{{ post.date | date: "%b %-d, %Y" }}</a>
<h2 class="h1 lh-condensed mt-0">
<a class="link-primary" title="{{ post.url | prepend: site.baseurl }}" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</h2>
<p>{{ post.content | strip_html | truncatewords:30 }}</p>
</div>
{% endfor %}
27 changes: 16 additions & 11 deletions writing.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
---
layout: page
layout: category_index
title: Writing
permalink: /writing/
category_name: writing
---

<!-- Choose which category you want to show posts for. -->
{% for post in site.categories.writing %}
<div class="container mx-auto py-2 mb-2 prose">
<a class="no-underline h5 bold text-accent" title="{{ post.url | prepend: site.baseurl }}" href="{{ post.url | prepend: site.baseurl }}">{{ post.date | date: "%b %-d, %Y" }}</a>
<h2 class="h1 lh-condensed mt-0">
<a class="link-primary" title="{{ post.url | prepend: site.baseurl }}" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</h2>
<p>{{ post.content | strip_html | truncatewords:30}}</p>
</div>
{% endfor %}
<!--
Set the front matter:
title = your page title and link name in the navigation
permalink = the url for the page, i.e. example.com/my-awesome-category
category_name = the name of the cateogry you want to use to group posts, you'll need to use the same name on post pages
Save this page in the root directory.
Use the same name for the filename as the permalink, i.e.
permalink: /my-awesome-category/
filename: my-awesome-category.html
-->

0 comments on commit c37680a

Please sign in to comment.