From 0a4c90e0317e63e8e99f7c578ff1251e874f1f2c Mon Sep 17 00:00:00 2001 From: Michael Rose <est.michael@gmail.com> Date: Sat, 5 Mar 2016 21:29:39 -0500 Subject: [PATCH] DRY up archives by using an include --- _includes/post-single.html | 8 ++++++++ _layouts/home.html | 9 +-------- _pages/category-archive.html | 9 +-------- _pages/collection-archive.html | 5 +---- _pages/recipes-archive.html | 9 +-------- _pages/tag-archive.html | 9 +-------- _pages/year-archive.html | 9 +-------- 7 files changed, 14 insertions(+), 44 deletions(-) create mode 100644 _includes/post-single.html diff --git a/_includes/post-single.html b/_includes/post-single.html new file mode 100644 index 00000000..e391187f --- /dev/null +++ b/_includes/post-single.html @@ -0,0 +1,8 @@ +<article itemscope itemtype="http://schema.org/CreativeWork"> + {% if post.link %} + <h2 class="link-post" itemprop="headline"><a href="{{ absurl }}{{ post.url }}">{{ post.title | markdownify | remove: "<p>" | remove: "</p>" }}</a> <a href="{{ post.link }}" target="_blank"><i class="fa fa-link"></i></a></h2> + {% else %} + <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}">{{ post.title | markdownify | remove: "<p>" | remove: "</p>" }}</a></h2> + {% if post.excerpt %}<p itemprop="description">{{ post.excerpt | strip_html | truncate: 160 }}</p>{% endif %} + {% endif %} +</article> \ No newline at end of file diff --git a/_layouts/home.html b/_layouts/home.html index 4d4dee22..e45ba57e 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -7,13 +7,6 @@ layout: default <div class="archive"> <h3><a href="{{ absurl }}/posts/">Recent Posts</a></h3> {% for post in site.posts limit:5 %} - <article itemscope itemtype="http://schema.org/CreativeWork"> - {% if post.link %} - <h2 class="link-post" itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2> - {% else %} - <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2> - <p itemprop="description">{{ post.excerpt | strip_html | truncate: 160 }}</p> - {% endif %} - </article> + {% include post-single.html %} {% endfor %} </div><!-- /#index --> \ No newline at end of file diff --git a/_pages/category-archive.html b/_pages/category-archive.html index 6e6f5126..9babd6d9 100644 --- a/_pages/category-archive.html +++ b/_pages/category-archive.html @@ -10,13 +10,6 @@ title: "Posts by Category" {% assign posts = group_items[forloop.index0] %} <h3>{{ category }}</h3> {% for post in posts %} - <article itemscope itemtype="http://schema.org/CreativeWork"> - {% if post.link %} - <h2 class="link-post" itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2> - {% else %} - <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2> - <p itemprop="description">{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}</p> - {% endif %} - </article> + {% include post-single.html %} {% endfor %} {% endfor %} \ No newline at end of file diff --git a/_pages/collection-archive.html b/_pages/collection-archive.html index e85819d9..e52157fd 100644 --- a/_pages/collection-archive.html +++ b/_pages/collection-archive.html @@ -16,10 +16,7 @@ permalink: /collection-archive/ {% endunless %} {% for post in collection.docs %} {% unless collection.output == false or collection.label == 'posts' %} - <article itemscope itemtype="http://schema.org/CreativeWork"> - <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2> - {% if post.excerpt %}<p itemprop="description">{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}</p>{% endif %} - </article> + {% include post-single.html %} {% endunless %} {% endfor %} {% endfor %} \ No newline at end of file diff --git a/_pages/recipes-archive.html b/_pages/recipes-archive.html index 5c396b8f..27643711 100644 --- a/_pages/recipes-archive.html +++ b/_pages/recipes-archive.html @@ -10,13 +10,6 @@ permalink: /recipes/ {% assign posts = group_items[forloop.index0] %} <h3>{{ category }}</h3> {% for post in posts %} - <article itemscope itemtype="http://schema.org/CreativeWork"> - {% if post.link %} - <h2 class="link-post" itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2> - {% else %} - <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2> - <p itemprop="description">{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}</p> - {% endif %} - </article> + {% include post-single.html %} {% endfor %} {% endfor %} \ No newline at end of file diff --git a/_pages/tag-archive.html b/_pages/tag-archive.html index 503904ef..c10941e5 100644 --- a/_pages/tag-archive.html +++ b/_pages/tag-archive.html @@ -10,13 +10,6 @@ title: "Posts by Tags" {% assign posts = group_items[forloop.index0] %} <h3>{{ tag }}</h3> {% for post in posts %} - <article itemscope itemtype="http://schema.org/CreativeWork"> - {% if post.link %} - <h2 class="link-post" itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2> - {% else %} - <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2> - <p itemprop="description">{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}</p> - {% endif %} - </article> + {% include post-single.html %} {% endfor %} {% endfor %} \ No newline at end of file diff --git a/_pages/year-archive.html b/_pages/year-archive.html index ebf708cd..984b6ff9 100644 --- a/_pages/year-archive.html +++ b/_pages/year-archive.html @@ -11,12 +11,5 @@ title: "Posts by Year" <h3>{{ year }}</h3> {% capture written_year %}{{ year }}{% endcapture %} {% endif %} - <article itemscope itemtype="http://schema.org/CreativeWork"> - {% if post.link %} - <h2 class="link-post" itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2> - {% else %} - <h2 itemprop="headline"><a href="{{ absurl }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2> - <p itemprop="description">{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}</p> - {% endif %} - </article> + {% include post-single.html %} {% endfor %} \ No newline at end of file