diff --git a/.eleventy.js b/.eleventy.js index 55c32d2..b387b3c 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -19,6 +19,8 @@ module.exports = function(eleventyConfig) { }); }); + eleventyConfig.addCollection("tagList", require("./_11ty/getTagList")); + eleventyConfig.addPassthroughCopy("img"); eleventyConfig.addPassthroughCopy("css"); diff --git a/.eleventyignore b/.eleventyignore index b43bf86..ec64229 100644 --- a/.eleventyignore +++ b/.eleventyignore @@ -1 +1,2 @@ README.md +_11ty/ diff --git a/_11ty/getTagList.js b/_11ty/getTagList.js new file mode 100644 index 0000000..6b2882a --- /dev/null +++ b/_11ty/getTagList.js @@ -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); +}; diff --git a/package.json b/package.json index 7a7e81d..205e5ea 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "homepage": "https://github.com/11ty/eleventy-base-blog#readme", "devDependencies": { - "@11ty/eleventy": "^0.4.0", + "@11ty/eleventy": "^0.5.3", "@11ty/eleventy-plugin-rss": "^1.0.2", "@11ty/eleventy-plugin-syntaxhighlight": "^1.0.5", "luxon": "^1.0.0", diff --git a/tags-list.njk b/tags-list.njk new file mode 100644 index 0000000..1e2fea4 --- /dev/null +++ b/tags-list.njk @@ -0,0 +1,10 @@ +--- +permalink: /tags/ +layout: layouts/home.njk +--- +

Tags

+ +{% for tag in collections.tagList %} + {% set tagUrl %}/tags/{{ tag }}/{% endset %} + {{ tag }} +{% endfor %} diff --git a/tags.njk b/tags.njk index 32cf598..cac955a 100644 --- a/tags.njk +++ b/tags.njk @@ -11,8 +11,9 @@ pagination: permalink: /tags/{{ tag }}/ layout: layouts/home.njk --- -

Tagged “{{ tag }}”

{% set postslist = collections[ tag ] %} {% include "postslist.njk" %} + +

See all tags.