Skip to content

Commit

Permalink
Support spaces in tags in base blog.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Mar 17, 2021
1 parent 2ccfbf9 commit 85fd949
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 21 deletions.
15 changes: 7 additions & 8 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ module.exports = function(eleventyConfig) {
return Math.min.apply(null, numbers);
});

eleventyConfig.addFilter("filterTagList", tags => {
// should match the list in tags.njk
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
})

// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set();
collection.getAll().forEach(function(item) {
if( "tags" in item.data ) {
let tags = item.data.tags;

// this list should match the `filter` list in tags.njk
tags.filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1)
.forEach(tag => tagSet.add(tag));
}
collection.getAll().forEach(item => {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
});

return [...tagSet];
Expand Down
11 changes: 9 additions & 2 deletions _includes/layouts/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ templateClass: tmpl-post
---
<h1>{{ title }}</h1>

<time datetime="{{ page.date | htmlDateString }}">{{ page.date | readableDate }}</time>

{%- for tag in tags | filterTagList %}
{%- set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{%- endfor %}

{{ content | safe }}

{%- set nextPost = collections.posts | getNextCollectionItem(page) %}
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{% if nextPost or previousPost %}
{%- if nextPost or previousPost %}
<hr>
<ul>
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %}
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %}
</ul>
{% endif %}
{%- endif %}
6 changes: 2 additions & 4 deletions _includes/postslist.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
<li class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}">
<a href="{{ post.url | url }}" class="postlist-link">{% if post.data.title %}{{ post.data.title }}{% else %}<code>{{ post.url }}</code>{% endif %}</a>
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
{% for tag in post.data.tags %}
{%- if collections.tagList.indexOf(tag) != -1 -%}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
{% for tag in post.data.tags | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{%- endif -%}
{% endfor %}
</li>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion posts/firstpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: This is my first post.
description: This is a post on My Blog about agile frameworks.
date: 2018-05-01
tags:
- another-tag
- another tag
layout: layouts/post.njk
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
Expand Down
2 changes: 1 addition & 1 deletion posts/fourthpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: This is my fourth post.
description: This is a post on My Blog about touchpoints and circling wagons.
date: 2018-09-30
tags: second-tag
tags: second tag
layout: layouts/post.njk
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
Expand Down
2 changes: 1 addition & 1 deletion posts/secondpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: This is my second post.
description: This is a post on My Blog about leveraging agile frameworks.
date: 2018-07-04
tags:
- number-2
- number 2
layout: layouts/post.njk
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
Expand Down
2 changes: 1 addition & 1 deletion posts/thirdpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: This is my third post.
description: This is a post on My Blog about win-win survival strategies.
date: 2018-08-24
tags:
- second-tag
- second tag
layout: layouts/post.njk
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
Expand Down
4 changes: 2 additions & 2 deletions tags-list.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ layout: layouts/home.njk
---
<h1>Tags</h1>

{% for tag in collections.tagList %}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
{% for tag in collections.tagList | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{% endfor %}
2 changes: 1 addition & 1 deletion tags.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pagination:
layout: layouts/home.njk
eleventyComputed:
title: Tagged “{{ tag }}
permalink: /tags/{{ tag }}/
permalink: /tags/{{ tag | slug }}/
---
<h1>Tagged “{{ tag }}”</h1>

Expand Down

0 comments on commit 85fd949

Please sign in to comment.