Skip to content

Commit

Permalink
Add tag list
Browse files Browse the repository at this point in the history
  • Loading branch information
dandevri committed Sep 6, 2019
1 parent d529024 commit 03bb4c5
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eleventy.js
Expand Up @@ -42,6 +42,7 @@ module.exports = function(config) {
return markdownIt.render(value);
});

config.addCollection("tagList", require("./_11ty/getTagList"));

return {
passthroughFileCopy: true,
Expand Down
38 changes: 38 additions & 0 deletions _11ty/getTagList.js
@@ -0,0 +1,38 @@
module.exports = function(collection) {
let tagSet = new Set();
collection.getAll().forEach(function(item) {
if( "tags" in item.data ) {
let tags = item.data.tags;

tags = tags.filter(function(item) {
switch(item) {
// this list should match the `filter` list in tags.njk
case "all":
case "nav":
case "post":
case "posts":
case "tagList":
case "link":
case "guide":
case "note":
case "weeknote":
case "journal":
case "project":
case "talks":
case "article":
case "essay":
return false;
}

return true;
});

for (const tag of tags) {
tagSet.add(tag);
}
}
});

// returning an array in addCollection works in Eleventy 0.5.3
return [...tagSet];
};
6 changes: 6 additions & 0 deletions pages/writing.njk
Expand Up @@ -8,6 +8,12 @@ permalink: writing/

{{ list.tag('notes', 'weeknotes', 'journal', 'guides', 'essays', 'links') }}

<p>I write about: {{ taglist }}</p>
{% for tag in collections.tagList %}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="tag">{{ tag }}</a>
{% endfor %}

<section class="article-list grid grid-l">
{%- for article in collections.article | reverse -%}
{% include 'components/atoms/article.njk' %}
Expand Down
12 changes: 12 additions & 0 deletions pages/writing/tags-list.njk
@@ -0,0 +1,12 @@
---
layout: layouts/default
permalink: /tags/
title: All tags
---

{% for tag in collections.tagList %}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="tag">{{ tag }}</a>
{% endfor %}

<p>See <a href="{{ '/tags/' | url }}">all tags</a>.</p>
36 changes: 36 additions & 0 deletions pages/writing/tags.njk
@@ -0,0 +1,36 @@
---
pagination:
data: collections
size: 1
alias: tag
filter:
- all
- nav
- post
- posts
- note
- weeknote
- project
- journal
- guide
- essay
- link
- tagList
- talks
- article
addAllPagesToCollections: true
layout: layouts/default
renderData:
title: Tagged “{{ tag }}
permalink: /tags/{{ tag }}/
---
<h1>Tagged “{{ tag }}”</h1>

<ol>
{% set taglist = collections[ tag ] %}
{% for post in taglist | reverse %}
<li><a href="{{ post.url | url }}">{{ post.data.title }}</a></li>
{% endfor %}
</ol>

<p>See <a href="{{ '/tags/' | url }}">all tags</a>.</p>
10 changes: 10 additions & 0 deletions posts/articles/example-post copy.md
@@ -0,0 +1,10 @@
---
title: Tech Review
subtitle: I've been working on this very website for quite some time.
description: I've been working on this very website for quite some time but always felt it was not finished.
slug: tech-review
date: 2019-09-06
tags: ['article', 'tech']
layout: layouts/post.njk
permalink: /articles/{{ slug }}/index.html
---

0 comments on commit 03bb4c5

Please sign in to comment.