Adds a /tags/ to list all valid tags
This commit is contained in:
parent
e3f3bc1cf2
commit
ef7783222d
@ -19,6 +19,8 @@ module.exports = function(eleventyConfig) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eleventyConfig.addCollection("tagList", require("./_11ty/getTagList"));
|
||||||
|
|
||||||
eleventyConfig.addPassthroughCopy("img");
|
eleventyConfig.addPassthroughCopy("img");
|
||||||
eleventyConfig.addPassthroughCopy("css");
|
eleventyConfig.addPassthroughCopy("css");
|
||||||
|
|
||||||
|
@ -1 +1,2 @@
|
|||||||
README.md
|
README.md
|
||||||
|
_11ty/
|
||||||
|
29
_11ty/getTagList.js
Normal file
29
_11ty/getTagList.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
module.exports = function(collection) {
|
||||||
|
let tagList = {};
|
||||||
|
collection.getAllSorted().forEach(function(item) {
|
||||||
|
if( "tags" in item.data ) {
|
||||||
|
let tags = item.data.tags;
|
||||||
|
if( typeof tags === "string" ) {
|
||||||
|
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":
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}).forEach(function(tag) {
|
||||||
|
tagList[tag] = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// returning an array in addCollection works in Eleventy 0.5.3
|
||||||
|
return Object.keys(tagList);
|
||||||
|
};
|
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
|
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@11ty/eleventy": "^0.4.0",
|
"@11ty/eleventy": "^0.5.3",
|
||||||
"@11ty/eleventy-plugin-rss": "^1.0.2",
|
"@11ty/eleventy-plugin-rss": "^1.0.2",
|
||||||
"@11ty/eleventy-plugin-syntaxhighlight": "^1.0.5",
|
"@11ty/eleventy-plugin-syntaxhighlight": "^1.0.5",
|
||||||
"luxon": "^1.0.0",
|
"luxon": "^1.0.0",
|
||||||
|
10
tags-list.njk
Normal file
10
tags-list.njk
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
permalink: /tags/
|
||||||
|
layout: layouts/home.njk
|
||||||
|
---
|
||||||
|
<h1>Tags</h1>
|
||||||
|
|
||||||
|
{% for tag in collections.tagList %}
|
||||||
|
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
|
||||||
|
<a href="{{ tagUrl | url }}" class="tag">{{ tag }}</a>
|
||||||
|
{% endfor %}
|
3
tags.njk
3
tags.njk
@ -11,8 +11,9 @@ pagination:
|
|||||||
permalink: /tags/{{ tag }}/
|
permalink: /tags/{{ tag }}/
|
||||||
layout: layouts/home.njk
|
layout: layouts/home.njk
|
||||||
---
|
---
|
||||||
|
|
||||||
<h1>Tagged “{{ tag }}”</h1>
|
<h1>Tagged “{{ tag }}”</h1>
|
||||||
|
|
||||||
{% set postslist = collections[ tag ] %}
|
{% set postslist = collections[ tag ] %}
|
||||||
{% include "postslist.njk" %}
|
{% include "postslist.njk" %}
|
||||||
|
|
||||||
|
<p>See <a href="/tags/">all tags</a>.</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user