From d6605146ac0a2088f6e4dafc06fe720e419ba7cf Mon Sep 17 00:00:00 2001 From: Michael Rose Date: Tue, 20 Mar 2018 12:45:28 -0400 Subject: [PATCH] Add posts, categories, category, tags, tag, and collection layouts Replace sample pages with hard coded HTML and Liquid in favor of a layout that does all the heavy lifting. Assign the appropriate `layout` via YAML Front Matter and away you go. --- _includes/documents-collection.html | 19 +++++++++ _includes/posts-category.html | 3 ++ _includes/posts-tag.html | 3 ++ _layouts/categories.html | 48 +++++++++++++++++++++ _layouts/category.html | 9 ++++ _layouts/collection.html | 9 ++++ _layouts/posts.html | 29 +++++++++++++ _layouts/tag.html | 9 ++++ _layouts/tags.html | 48 +++++++++++++++++++++ _sass/minimal-mistakes/_page.scss | 66 +++++++++++++++++++++++++++++ test/_pages/category-archive.html | 2 +- test/_pages/recipes-archive.html | 2 +- test/_pages/tag-archive.html | 2 +- 13 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 _includes/documents-collection.html create mode 100644 _includes/posts-category.html create mode 100644 _includes/posts-tag.html create mode 100644 _layouts/categories.html create mode 100644 _layouts/category.html create mode 100644 _layouts/collection.html create mode 100644 _layouts/posts.html create mode 100644 _layouts/tag.html create mode 100644 _layouts/tags.html diff --git a/_includes/documents-collection.html b/_includes/documents-collection.html new file mode 100644 index 00000000..13b4006e --- /dev/null +++ b/_includes/documents-collection.html @@ -0,0 +1,19 @@ +{% assign entries = site[include.collection] %} + +{% if include.sort_by == 'title' %} + {% if include.sort_order == 'reverse' %} + {% assign entries = entries | sort: 'title' | reverse %} + {% else %} + {% assign entries = entries | sort: 'title' %} + {% endif %} +{% elsif include.sort_by == 'date' %} + {% if include.sort_order == 'reverse' %} + {% assign entries = entries | sort: 'date' | reverse %} + {% else %} + {% assign entries = entries | sort: 'date' %} + {% endif %} +{% endif %} + +{%- for post in entries -%} + {% include archive-single.html %} +{%- endfor -%} diff --git a/_includes/posts-category.html b/_includes/posts-category.html new file mode 100644 index 00000000..98be3e96 --- /dev/null +++ b/_includes/posts-category.html @@ -0,0 +1,3 @@ +{%- for post in site.categories[include.taxonomy] -%} + {% include archive-single.html %} +{%- endfor -%} diff --git a/_includes/posts-tag.html b/_includes/posts-tag.html new file mode 100644 index 00000000..180a2f31 --- /dev/null +++ b/_includes/posts-tag.html @@ -0,0 +1,3 @@ +{%- for post in site.tags[include.taxonomy] -%} + {% include archive-single.html %} +{%- endfor -%} diff --git a/_layouts/categories.html b/_layouts/categories.html new file mode 100644 index 00000000..ca3d7ec3 --- /dev/null +++ b/_layouts/categories.html @@ -0,0 +1,48 @@ +--- +layout: archive +--- + +{{ content }} + + + +{% assign categories_max = 0 %} +{% for category in site.categories %} + {% if category[1].size > categories_max %} + {% assign categories_max = category[1].size %} + {% endif %} +{% endfor %} + +{% for i in (1..categories_max) reversed %} + {% for category in site.categories %} + {% if category[1].size == i %} +
+

{{ category[0] }}

+
+ {% for post in category.last %} + {% include archive-single.html %} + {% endfor %} +
+ {{ site.data.text[site.locale].back_to_top | default: 'Back to Top' }} ↑ +
+ {% endif %} + {% endfor %} +{% endfor %} diff --git a/_layouts/category.html b/_layouts/category.html new file mode 100644 index 00000000..1644e3ce --- /dev/null +++ b/_layouts/category.html @@ -0,0 +1,9 @@ +--- +layout: archive +--- + +{{ content }} + +
+ {% include posts-category.html taxonomy=page.taxonomy %} +
diff --git a/_layouts/collection.html b/_layouts/collection.html new file mode 100644 index 00000000..0c7ceb4c --- /dev/null +++ b/_layouts/collection.html @@ -0,0 +1,9 @@ +--- +layout: archive +--- + +{{ content }} + +
+ {% include documents-collection.html collection=page.collection sort_by=page.sort_by sort_order=page.sort_order %} +
diff --git a/_layouts/posts.html b/_layouts/posts.html new file mode 100644 index 00000000..a5947896 --- /dev/null +++ b/_layouts/posts.html @@ -0,0 +1,29 @@ +--- +layout: archive +--- + +{{ content }} + + + +{% assign postsByYear = site.posts | group_by_exp: 'post', 'post.date | date: "%Y"' %} +{% for year in postsByYear %} +
+

{{ year.name }}

+
+ {% for post in year.items %} + {% include archive-single.html %} + {% endfor %} +
+ {{ site.data.text[site.locale].back_to_top | default: 'Back to Top' }} ↑ +
+{% endfor %} \ No newline at end of file diff --git a/_layouts/tag.html b/_layouts/tag.html new file mode 100644 index 00000000..33971e04 --- /dev/null +++ b/_layouts/tag.html @@ -0,0 +1,9 @@ +--- +layout: archive +--- + +{{ content }} + +
+ {% include posts-tag.html taxonomy=page.taxonomy %} +
diff --git a/_layouts/tags.html b/_layouts/tags.html new file mode 100644 index 00000000..b5855439 --- /dev/null +++ b/_layouts/tags.html @@ -0,0 +1,48 @@ +--- +layout: archive +--- + +{{ content }} + + + +{% assign tags_max = 0 %} +{% for tag in site.tags %} + {% if tag[1].size > tags_max %} + {% assign tags_max = tag[1].size %} + {% endif %} +{% endfor %} + +{% for i in (1..tags_max) reversed %} + {% for tag in site.tags %} + {% if tag[1].size == i %} +
+

{{ tag[0] }}

+
+ {% for post in tag.last %} + {% include archive-single.html %} + {% endfor %} +
+ {{ site.data.text[site.locale].back_to_top | default: 'Back to Top' }} ↑ +
+ {% endif %} + {% endfor %} +{% endfor %} diff --git a/_sass/minimal-mistakes/_page.scss b/_sass/minimal-mistakes/_page.scss index c5c1f380..8e5c5d93 100644 --- a/_sass/minimal-mistakes/_page.scss +++ b/_sass/minimal-mistakes/_page.scss @@ -295,6 +295,72 @@ } } +.taxonomy-section { + margin-bottom: 2em; + padding-bottom: 1em; + + &:not(:last-child) { + border-bottom: solid 1px $border-color; + } + + .archive__item-title { + margin-top: 0; + } + + .archive__subtitle { + border: 0; + } + + + .taxonomy-section { + margin-top: 2em; + } +} + +.taxonomy-title { + margin-bottom: 0.5em; + color: lighten($text-color, 60%); +} + +.taxonomy-count { + color: lighten($text-color, 50%); +} + +.taxonomy-index { + display: grid; + grid-column-gap: 2em; + grid-template-columns: repeat(2, 1fr); + margin: 0; + padding: 0; + font-size: 0.75em; + list-style: none; + + @include breakpoint($large) { + grid-template-columns: repeat(3, 1fr); + } + + a { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + padding: 0.25em 0; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; + color: inherit; + text-decoration: none; + border-bottom: 1px solid $border-color; + } +} + +.back-to-top { + display: block; + color: lighten($text-color, 50%); + font-size: 0.6em; + text-transform: uppercase; + text-align: right; + text-decoration: none; +} + /* Comments ========================================================================== */ diff --git a/test/_pages/category-archive.html b/test/_pages/category-archive.html index c9e03e15..020df61f 100644 --- a/test/_pages/category-archive.html +++ b/test/_pages/category-archive.html @@ -1,6 +1,6 @@ --- layout: archive -permalink: /categories/ +permalink: /categories-archive/ title: "Posts by Category" author_profile: true --- diff --git a/test/_pages/recipes-archive.html b/test/_pages/recipes-archive.html index b5e2dfc2..f4ccce1c 100644 --- a/test/_pages/recipes-archive.html +++ b/test/_pages/recipes-archive.html @@ -1,7 +1,7 @@ --- layout: archive title: "Recipes" -permalink: /recipes/ +permalink: /recipes-archive/ author_profile: false --- diff --git a/test/_pages/tag-archive.html b/test/_pages/tag-archive.html index b30a57f5..a78cd38d 100644 --- a/test/_pages/tag-archive.html +++ b/test/_pages/tag-archive.html @@ -1,6 +1,6 @@ --- layout: archive -permalink: /tags/ +permalink: /tags-archive/ title: "Posts by Tag" author_profile: true ---