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); 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 // Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) { eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set(); let tagSet = new Set();
collection.getAll().forEach(function(item) { collection.getAll().forEach(item => {
if( "tags" in item.data ) { (item.data.tags || []).forEach(tag => tagSet.add(tag));
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));
}
}); });
return [...tagSet]; return [...tagSet];

View File

@ -4,14 +4,21 @@ templateClass: tmpl-post
--- ---
<h1>{{ title }}</h1> <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 }} {{ content | safe }}
{%- set nextPost = collections.posts | getNextCollectionItem(page) %} {%- set nextPost = collections.posts | getNextCollectionItem(page) %}
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %} {%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{% if nextPost or previousPost %} {%- if nextPost or previousPost %}
<hr> <hr>
<ul> <ul>
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %} {%- 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 %} {%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %}
</ul> </ul>
{% endif %} {%- endif %}

View File

@ -3,11 +3,9 @@
<li class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}"> <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> <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> <time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
{% for tag in post.data.tags %} {% for tag in post.data.tags | filterTagList %}
{%- if collections.tagList.indexOf(tag) != -1 -%} {% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a> <a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{%- endif -%}
{% endfor %} {% endfor %}
</li> </li>
{% endfor %} {% endfor %}

View File

@ -3,7 +3,7 @@ title: This is my first post.
description: This is a post on My Blog about agile frameworks. description: This is a post on My Blog about agile frameworks.
date: 2018-05-01 date: 2018-05-01
tags: tags:
- another-tag - another tag
layout: layouts/post.njk 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. 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. title: This is my fourth post.
description: This is a post on My Blog about touchpoints and circling wagons. description: This is a post on My Blog about touchpoints and circling wagons.
date: 2018-09-30 date: 2018-09-30
tags: second-tag tags: second tag
layout: layouts/post.njk 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. 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. description: This is a post on My Blog about leveraging agile frameworks.
date: 2018-07-04 date: 2018-07-04
tags: tags:
- number-2 - number 2
layout: layouts/post.njk 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. 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. description: This is a post on My Blog about win-win survival strategies.
date: 2018-08-24 date: 2018-08-24
tags: tags:
- second-tag - second tag
layout: layouts/post.njk 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. 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> <h1>Tags</h1>
{% for tag in collections.tagList %} {% for tag in collections.tagList | filterTagList %}
{% set tagUrl %}/tags/{{ tag }}/{% endset %} {% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a> <a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{% endfor %} {% endfor %}

View File

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