├── .gitignore
├── www
├── categories
│ ├── index.html
│ ├── books
│ │ └── index.html
│ ├── possums
│ │ └── index.html
│ ├── sports
│ │ └── index.html
│ ├── technologies-from-the-future
│ │ └── index.html
│ └── hardware
│ │ └── index.html
└── blog
│ ├── five
│ └── index.html
│ ├── one
│ └── index.html
│ ├── six
│ └── index.html
│ ├── two
│ └── index.html
│ ├── three
│ └── index.html
│ └── four
│ └── index.html
├── src
├── blog
│ ├── blog.11tydata.js
│ ├── five.njk
│ ├── one.njk
│ ├── six.njk
│ ├── three.njk
│ ├── two.njk
│ └── four.njk
├── _includes
│ └── postslist.njk
├── categories-list.njk
└── categories.njk
├── package.json
└── eleventy.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/www/categories/index.html:
--------------------------------------------------------------------------------
1 |
Categories
2 |
3 |
6 |
--------------------------------------------------------------------------------
/www/blog/five/index.html:
--------------------------------------------------------------------------------
1 |
2 | Blog Post Five
3 |
4 | tags=["posts"]
5 | category="Books"
6 |
--------------------------------------------------------------------------------
/www/blog/one/index.html:
--------------------------------------------------------------------------------
1 |
2 | Blog Post One
3 |
4 | tags=["posts"]
5 | category="Hardware"
6 |
--------------------------------------------------------------------------------
/www/blog/six/index.html:
--------------------------------------------------------------------------------
1 |
2 | Blog Post Six
3 |
4 | tags=["posts"]
5 | category="Possums"
6 |
--------------------------------------------------------------------------------
/www/blog/two/index.html:
--------------------------------------------------------------------------------
1 |
2 | Blog Post Two
3 |
4 | tags=["posts"]
5 | category="Hardware"
6 |
--------------------------------------------------------------------------------
/www/blog/three/index.html:
--------------------------------------------------------------------------------
1 |
2 | Blog Post Three
3 |
4 | tags=["posts"]
5 | category="Sports"
6 |
--------------------------------------------------------------------------------
/www/blog/four/index.html:
--------------------------------------------------------------------------------
1 |
2 | Blog Post Four
3 |
4 | tags=["posts"]
5 | category="Technologies from the Future"
6 |
--------------------------------------------------------------------------------
/src/blog/blog.11tydata.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | tags: [
3 | "posts"
4 | ],
5 | // "layout": "layouts/post.njk",
6 | };
7 |
--------------------------------------------------------------------------------
/src/_includes/postslist.njk:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/www/categories/books/index.html:
--------------------------------------------------------------------------------
1 | Tagged “Books”
6 |
7 |
8 | See all tags.
--------------------------------------------------------------------------------
/www/categories/possums/index.html:
--------------------------------------------------------------------------------
1 | Tagged “Possums”
6 |
7 |
8 | See all tags.
--------------------------------------------------------------------------------
/src/blog/five.njk:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blog Post Five
3 | category: Books
4 | ---
5 |
6 | {{ title }}
7 |
8 | tags={{ tags | dump | safe }}
9 | category={{ category | dump | safe }}
10 |
--------------------------------------------------------------------------------
/src/blog/one.njk:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blog Post One
3 | category: Hardware
4 | ---
5 |
6 | {{ title }}
7 |
8 | tags={{ tags | dump | safe }}
9 | category={{ category | dump | safe }}
10 |
--------------------------------------------------------------------------------
/src/blog/six.njk:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blog Post Six
3 | category: Possums
4 | ---
5 |
6 | {{ title }}
7 |
8 | tags={{ tags | dump | safe }}
9 | category={{ category | dump | safe }}
10 |
--------------------------------------------------------------------------------
/src/blog/three.njk:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blog Post Three
3 | category: Sports
4 | ---
5 |
6 | {{ title }}
7 |
8 | tags={{ tags | dump | safe }}
9 | category={{ category | dump | safe }}
10 |
--------------------------------------------------------------------------------
/src/blog/two.njk:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blog Post Two
3 | category: Hardware
4 | ---
5 |
6 | {{ title }}
7 |
8 | tags={{ tags | dump | safe }}
9 | category={{ category | dump | safe }}
10 |
--------------------------------------------------------------------------------
/www/categories/sports/index.html:
--------------------------------------------------------------------------------
1 | Tagged “Sports”
6 |
7 |
8 | See all tags.
--------------------------------------------------------------------------------
/src/blog/four.njk:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blog Post Four
3 | category: Technologies from the Future
4 | ---
5 |
6 | {{ title }}
7 |
8 | tags={{ tags | dump | safe }}
9 | category={{ category | dump | safe }}
10 |
--------------------------------------------------------------------------------
/www/categories/technologies-from-the-future/index.html:
--------------------------------------------------------------------------------
1 | Tagged “Technologies from the Future”
6 |
7 |
8 | See all tags.
--------------------------------------------------------------------------------
/www/categories/hardware/index.html:
--------------------------------------------------------------------------------
1 | Tagged “Hardware”
8 |
9 |
10 | See all tags.
--------------------------------------------------------------------------------
/src/categories-list.njk:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /categories/
3 | # layout: layouts/home.njk
4 | ---
5 | Categories
6 |
7 |
8 | {% for category in collections.categories %}
9 | {%- set categoryUrl -%}/categories/{{ category | slugify }}/{%- endset -%}
10 | - {{ category }}
11 | {% endfor %}
12 |
13 |
--------------------------------------------------------------------------------
/src/categories.njk:
--------------------------------------------------------------------------------
1 | ---
2 | pagination:
3 | data: collections.categories
4 | size: 1
5 | alias: category
6 | addAllPagesToCollections: true
7 | # layout: layouts/home.njk
8 | eleventyComputed:
9 | title: Tagged “{{ category }}”
10 | permalink: "/categories/{{ category | slugify }}/"
11 | ---
12 | {{ title }}
13 |
14 | {%- set postslist = collections.categories[category] -%}
15 | {% include "postslist.njk" %}
16 |
17 | See all tags.
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "11ty-2865",
3 | "version": "1.0.0",
4 | "author": "Peter deHaan ",
5 | "devDependencies": {
6 | "@11ty/eleventy": "^2.0.0"
7 | },
8 | "keywords": [],
9 | "license": "MPL-2.0",
10 | "main": "index.js",
11 | "scripts": {
12 | "build": "eleventy",
13 | "postbuild": "# npx prettier www --write",
14 | "prebuild": "rm -rf www",
15 | "test": "echo \"Error: no test specified\" && exit 1"
16 | },
17 | "description": ""
18 | }
19 |
--------------------------------------------------------------------------------
/eleventy.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
3 | * @returns {ReturnType}
4 | */
5 | module.exports = function (eleventyConfig) {
6 | // Create a custom collection of unique categories and related posts.
7 | eleventyConfig.addCollection("categories", function (collection) {
8 | const _getAllCategories = eleventyConfig.getFilter("getAllCategories");
9 | const posts = collection.getFilteredByGlob("src/blog/*.njk");
10 | // Get all unique categories from our `posts[]` array.
11 | const categories = _getAllCategories(posts);
12 | const categoryMap = categories.reduce((map, category) => {
13 | // Get all pages from our `posts` collection wwith the specified `category`.
14 | const categoryPosts = posts.filter(post => post.data.category === category);
15 | return map.set(category, categoryPosts);
16 | }, new Map());
17 | // Convert category Map to Object.
18 | return Object.fromEntries(categoryMap);
19 | });
20 |
21 | eleventyConfig.addFilter("getAllCategories", function (collection) {
22 | const categorySet = collection.reduce((set, { data }) => {
23 | if (data.category && !set.has(data.category)) {
24 | console.log(`Adding ${data.category}`);
25 | set.add(data.category);
26 | }
27 | return set;
28 | }, new Set());
29 | return Array.from(categorySet).sort();
30 | });
31 |
32 | return {
33 | dir: {
34 | input: "src",
35 | output: "www",
36 | },
37 | };
38 | };
39 |
--------------------------------------------------------------------------------