├── .gitignore ├── src ├── blog │ ├── blog.11tydata.js │ ├── 2020-01-01-post-number-one.liquid │ ├── 2020-01-03-post-number-two.liquid │ ├── 2020-01-05-post-number-three.liquid │ ├── 2020-01-08-post-number-four.liquid │ ├── 2020-01-13-post-number-six.liquid │ ├── 2020-01-15-post-number-seven.liquid │ └── 2020-01-10-post-number-five.liquid ├── _includes │ └── blog-summary.liquid └── pages │ ├── index.liquid │ └── debug.liquid ├── www ├── 1 │ └── index.html ├── 2 │ └── index.html ├── blog │ ├── 2020-01-01-post-number-one │ │ └── index.html │ ├── 2020-01-03-post-number-two │ │ └── index.html │ ├── 2020-01-08-post-number-four │ │ └── index.html │ ├── 2020-01-05-post-number-three │ │ └── index.html │ ├── 2020-01-13-post-number-six │ │ └── index.html │ ├── 2020-01-15-post-number-seven │ │ └── index.html │ └── 2020-01-10-post-number-five │ │ └── index.html ├── index.html └── debug │ └── index.html ├── README.md ├── .eleventy.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /src/blog/blog.11tydata.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | tags: ["blog"] 3 | }; 4 | -------------------------------------------------------------------------------- /src/_includes/blog-summary.liquid: -------------------------------------------------------------------------------- 1 |
  • {{ post.data.title }}{{ post.date | localeDateString }}
  • 2 | -------------------------------------------------------------------------------- /www/blog/2020-01-01-post-number-one/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number one

    3 |
    4 | 5 |

    This is my blog.

    6 | 7 | 12 | -------------------------------------------------------------------------------- /www/blog/2020-01-03-post-number-two/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number two

    3 |
    4 | 5 |

    This is my blog.

    6 | 7 | 12 | -------------------------------------------------------------------------------- /www/blog/2020-01-08-post-number-four/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number four

    3 |
    4 | 5 |

    This is my blog.

    6 | 7 | 12 | -------------------------------------------------------------------------------- /www/blog/2020-01-05-post-number-three/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number three

    3 |
    4 | 5 |

    This is my blog.

    6 | 7 | 12 | -------------------------------------------------------------------------------- /www/blog/2020-01-13-post-number-six/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number six

    3 |
    4 | 5 |

    This is my blog.

    6 | 7 | 12 | -------------------------------------------------------------------------------- /www/blog/2020-01-15-post-number-seven/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number seven

    3 |
    4 | 5 |

    This is my blog.

    6 | 7 | 12 | -------------------------------------------------------------------------------- /src/blog/2020-01-01-post-number-one.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number one 3 | author: Jane Doe 4 | tags: 5 | - liquidjs 6 | --- 7 | 8 |
    9 |

    {{ title }}

    10 |
    11 | 12 |

    This is my blog.

    13 | 14 | -------------------------------------------------------------------------------- /src/blog/2020-01-03-post-number-two.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number two 3 | author: Jane Doe 4 | tags: 5 | - nunjucks 6 | --- 7 | 8 |
    9 |

    {{ title }}

    10 |
    11 | 12 |

    This is my blog.

    13 | 14 | -------------------------------------------------------------------------------- /www/2/index.html: -------------------------------------------------------------------------------- 1 |

    This is the Homepage.

    2 |

    There are many like it, but this one is mine.

    3 | 4 |
    5 |

    Looping over a collection (max 3 posts per page)

    6 | 12 |
    13 | -------------------------------------------------------------------------------- /src/blog/2020-01-05-post-number-three.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number three 3 | author: John Doe 4 | tags: 5 | - liquidjs 6 | --- 7 | 8 |
    9 |

    {{ title }}

    10 |
    11 | 12 |

    This is my blog.

    13 | 14 | -------------------------------------------------------------------------------- /src/blog/2020-01-08-post-number-four.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number four 3 | author: Jane Doe 4 | tags: 5 | - graphql 6 | --- 7 | 8 |
    9 |

    {{ title }}

    10 |
    11 | 12 |

    This is my blog.

    13 | 14 | -------------------------------------------------------------------------------- /src/blog/2020-01-13-post-number-six.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number six 3 | author: Janet Doe 4 | tags: 5 | - tailwindcss 6 | --- 7 | 8 |
    9 |

    {{ title }}

    10 |
    11 | 12 |

    This is my blog.

    13 | 14 | -------------------------------------------------------------------------------- /src/blog/2020-01-15-post-number-seven.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number seven 3 | author: Janine Doe 4 | tags: 5 | - github-actions 6 | --- 7 | 8 |
    9 |

    {{ title }}

    10 |
    11 | 12 |

    This is my blog.

    13 | 14 | -------------------------------------------------------------------------------- /www/blog/2020-01-10-post-number-five/index.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Post number five

    3 |
    4 | 5 |

    6 | This is my blog. I have overwritten the content date. Instead of using the 7 | filename, it now uses a hardcoded date from the frontmatter. 8 |

    9 | 10 | 15 | -------------------------------------------------------------------------------- /src/blog/2020-01-10-post-number-five.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Post number five 3 | author: Janie Doe 4 | tags: 5 | - typescript 6 | date: 2020-01-15 7 | --- 8 | 9 |
    10 |

    {{ title }}

    11 |
    12 | 13 |

    This is my blog. I have overwritten the content date. Instead of using the filename, it now uses a hardcoded date from the frontmatter.

    14 | 15 | -------------------------------------------------------------------------------- /src/pages/index.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Home 3 | pagination: 4 | data: collections.blogRecentByTags 5 | size: 3 6 | alias: posts 7 | permalink: "{% if pagination.pageNumber > 0 %}{{ pagination.pageNumber }}{% endif %}/" 8 | --- 9 | 10 |

    This is the Homepage.

    11 |

    There are many like it, but this one is mine.

    12 | 13 |
    14 |

    Looping over a collection (max {{ pagination.size }} posts per page)

    15 | 20 |
    21 | -------------------------------------------------------------------------------- /www/1/index.html: -------------------------------------------------------------------------------- 1 |

    This is the Homepage.

    2 |

    There are many like it, but this one is mine.

    3 | 4 |
    5 |

    Looping over a collection (max 3 posts per page)

    6 | 22 |
    23 | -------------------------------------------------------------------------------- /www/index.html: -------------------------------------------------------------------------------- 1 |

    This is the Homepage.

    2 |

    There are many like it, but this one is mine.

    3 | 4 |
    5 |

    Looping over a collection (max 3 posts per page)

    6 | 22 |
    23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 11ty-1587-pagination 2 | 3 | This repo shows how you can use 11ty's [`pagination`](https://www.11ty.dev/docs/pagination/) feature in the front-matter to loop over a collection and dynamically create some archives. 4 | 5 | The main /index.html archive page is generated from the ./src/pages/index.liquid file, which loops over the custom `blogRecentByTags` collection and displays 3 blog posts per page. The initial loop iteration over the `blogRecentByTags` collection will generate the /index.html page, while subsequent pages use the `permalink` key in the frontmatter to dynamically set the output file name to /1/index.html, /2/index.html; where /1/ and /2/ are the current value of `pagination.pageNumber`. 6 | 7 | The paginated archive page blog posts are displayed using `{% for post in posts %}...{% endfor %}` loop, where `posts` is the current pagination `alias` value. 8 | -------------------------------------------------------------------------------- /.eleventy.js: -------------------------------------------------------------------------------- 1 | const del = require("del").sync; 2 | 3 | module.exports = (eleventyConfig) => { 4 | // Purge the output directory before rebuiding site. 5 | del("./www"); 6 | 7 | // Sort these custom collections by descending date (newest first). 8 | eleventyConfig.addCollection("blogRecentByTags", (collectionApi) => collectionApi.getFilteredByTags("blog").sort(sortDateDesc)); 9 | eleventyConfig.addCollection("blogRecentByGlob", (collectionApi) => collectionApi.getFilteredByGlob("src/blog/*.liquid").sort(sortDateDesc)); 10 | 11 | eleventyConfig.addFilter("localeDateString", date => new Date(date).toLocaleDateString()); 12 | 13 | // https://www.11ty.dev/docs/data-deep-merge/ 14 | eleventyConfig.setDataDeepMerge(true); 15 | 16 | return { 17 | dir: { 18 | input: "src", 19 | output: "www" 20 | } 21 | }; 22 | }; 23 | 24 | function sortDateDesc(a, b) { 25 | return b.date - a.date; 26 | } 27 | -------------------------------------------------------------------------------- /src/pages/debug.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Home 3 | permalink: /debug/ 4 | --- 5 | 6 |

    This is the Homepage.

    7 |

    There are many like it, but this one is mine.

    8 | 9 |
    10 |

    `collections.blog` and liquidjs loop

    11 | {%- assign recentBlogs = collections.blog | reverse | slice: 0, 3 -%} 12 | 17 |
    18 | 19 |
    20 | 21 |
    22 |

    Custom `collections.blogRecentByTags` collection

    23 | 28 |
    29 | 30 |
    31 | 32 |
    33 |

    Custom `collections.blogRecentByGlob` collection

    34 | 39 |
    40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "11ty-1587-pagination", 3 | "description": "This repo shows how you can use 11ty's `pagination` feature in the front-matter to loop over a collection and dynamically create some archives.", 4 | "version": "1.0.0", 5 | "author": "Peter deHaan (https://about.me/peterdehaan)", 6 | "bugs": { 7 | "url": "https://github.com/pdehaan/11ty-1587-pagination/issues" 8 | }, 9 | "dependencies": {}, 10 | "devDependencies": { 11 | "@11ty/eleventy": "^0.11.1", 12 | "del": "^6.0.0", 13 | "prettier": "^2.2.1" 14 | }, 15 | "homepage": "https://github.com/pdehaan/11ty-1587-pagination#readme", 16 | "keywords": [], 17 | "license": "MPL-2.0", 18 | "main": "index.js", 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/pdehaan/11ty-1587-pagination.git" 22 | }, 23 | "scripts": { 24 | "build": "eleventy", 25 | "postbuild": "prettier www --write", 26 | "test": "echo \"Error: no test specified\" && exit 1" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /www/debug/index.html: -------------------------------------------------------------------------------- 1 |

    This is the Homepage.

    2 |

    There are many like it, but this one is mine.

    3 | 4 |
    5 |

    `collections.blog` and liquidjs loop

    6 | 22 |
    23 | 24 |
    25 | 26 |
    27 |

    Custom `collections.blogRecentByTags` collection

    28 | 64 |
    65 | 66 |
    67 | 68 |
    69 |

    Custom `collections.blogRecentByGlob` collection

    70 | 106 |
    107 | --------------------------------------------------------------------------------