Support spaces in tags in base blog.

This commit is contained in:
Zach Leatherman 2021-03-17 16:29:07 -05:00
parent 2ccfbf9244
commit 85fd94918e
9 changed files with 25 additions and 21 deletions

View File

@ -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];

View File

@ -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 %}

View File

@ -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 %}

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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 %}

View File

@ -13,7 +13,7 @@ pagination:
layout: layouts/home.njk
eleventyComputed:
title: Tagged “{{ tag }}”
permalink: /tags/{{ tag }}/
permalink: /tags/{{ tag | slug }}/
---
<h1>Tagged “{{ tag }}”</h1>