├── .gitignore ├── www ├── page-1 │ └── index.html ├── page-2 │ └── index.html ├── page-3 │ └── index.html ├── page-4 │ └── index.html ├── page-5 │ └── index.html ├── foo │ └── index.html └── index.html ├── src ├── foo.liquid ├── _data │ └── pages.js ├── index.liquid └── pagination.liquid ├── package.json └── .eleventy.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /www/page-1/index.html: -------------------------------------------------------------------------------- 1 |

Page 1

2 | 3 | -------------------------------------------------------------------------------- /www/page-2/index.html: -------------------------------------------------------------------------------- 1 |

Page 2

2 | 3 | -------------------------------------------------------------------------------- /www/page-3/index.html: -------------------------------------------------------------------------------- 1 |

Page 3

2 | 3 | -------------------------------------------------------------------------------- /www/page-4/index.html: -------------------------------------------------------------------------------- 1 |

Page 4

2 | 3 | -------------------------------------------------------------------------------- /www/page-5/index.html: -------------------------------------------------------------------------------- 1 |

Page 5

2 | 3 | -------------------------------------------------------------------------------- /www/foo/index.html: -------------------------------------------------------------------------------- 1 |

2 | 5 | -------------------------------------------------------------------------------- /src/foo.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mock page 3 | date: 2022-01-09 4 | tags: 5 | - page 6 | --- 7 | 8 |

{{ p.title }}

9 | 10 | -------------------------------------------------------------------------------- /src/_data/pages.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { title: "Page 1", date: "2022-02-14" }, 3 | { title: "Page 2", date: "2021-07-24" }, 4 | { title: "Page 3", date: "2022-03-01" }, 5 | { title: "Page 4", date: "2020-10-25" }, 6 | { title: "Page 5", date: "2019-12-03" }, 7 | ]; 8 | -------------------------------------------------------------------------------- /src/index.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | --- 4 | 5 | 10 | 11 |
12 | {{ collections.page | inspect }}
13 | 
14 | -------------------------------------------------------------------------------- /src/pagination.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | pagination: 3 | data: pages 4 | size: 1 5 | alias: p 6 | addAllPagesToCollections: true 7 | permalink: "{{ p.title | slugify }}/" 8 | tags: 9 | - page 10 | --- 11 | 12 |

{{ p.title }}

13 | 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "11ty-paginated-date", 3 | "description": "", 4 | "version": "1.0.0", 5 | "author": "Peter deHaan ", 6 | "bugs": { 7 | "url": "https://github.com/pdehaan/11ty-1226/issues" 8 | }, 9 | "devDependencies": { 10 | "@11ty/eleventy": "^1.0.0" 11 | }, 12 | "homepage": "https://github.com/pdehaan/11ty-1226#readme", 13 | "keywords": [], 14 | "license": "MPL-2.0", 15 | "main": ".eleventy.js", 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/pdehaan/11ty-1226.git" 19 | }, 20 | "scripts": { 21 | "build": "eleventy", 22 | "test": "echo \"Error: no test specified\" && exit 1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.eleventy.js: -------------------------------------------------------------------------------- 1 | const inspect = require("node:util").inspect; 2 | 3 | module.exports = (eleventyConfig) => { 4 | eleventyConfig.addFilter("inspect", function (value) { 5 | return inspect(value, { sorted: true }); 6 | }); 7 | 8 | eleventyConfig.addFilter("date_format", function (value) { 9 | return new Date(value).toLocaleDateString(["en-US"]); 10 | }); 11 | 12 | eleventyConfig.addCollection("page", function (collectionApi) { 13 | // Get all pages with the tag "page". 14 | const p = collectionApi.getFilteredByTag("page"); 15 | return p.sort((a, b) => { 16 | // `_.data.p.date` if it's via pagination, otherwise `_.date`. 17 | a.date = a.data.p?.date ? new Date(a.data.p.date) : a.date; 18 | b.date = b.data.p?.date ? new Date(b.data.p.date) : b.date; 19 | // Return pages sorted by date, in descending order. 20 | return b.date - a.date; 21 | }); 22 | }); 23 | 24 | return { 25 | dir: { 26 | input: "src", 27 | output: "www", 28 | }, 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /www/index.html: -------------------------------------------------------------------------------- 1 | 9 | 10 |
 11 | [
 12 |   {
 13 |     checkTemplateContent: true,
 14 |     data: {
 15 |       collections: [Object],
 16 |       eleventy: [Object],
 17 |       p: [Object],
 18 |       page: [Object],
 19 |       pages: [Array],
 20 |       pagination: [Object],
 21 |       permalink: '{{ p.title | slugify }}/',
 22 |       pkg: [Object],
 23 |       tags: [Array]
 24 |     },
 25 |     date: 2022-03-01T00:00:00.000Z,
 26 |     filePathStem: '/pagination',
 27 |     fileSlug: 'pagination',
 28 |     inputPath: './src/pagination.liquid',
 29 |     outputPath: 'www/page-3/index.html',
 30 |     pageNumber: 2,
 31 |     template: Template {
 32 |       _config: [TemplateConfig],
 33 |       _extensionMap: [EleventyExtensionMap],
 34 |       _frontMatterDataCache: [Object],
 35 |       _logger: [ConsoleLogger],
 36 |       _stats: [Promise],
 37 |       _templateRender: [TemplateRender],
 38 |       _usePermalinkRoot: undefined,
 39 |       behavior: [TemplateBehavior],
 40 |       computedData: [ComputedData],
 41 |       dataCache: [Object],
 42 |       extraOutputSubdirectory: '',
 43 |       filePathStem: '/pagination',
 44 |       fileSlug: [TemplateFileSlug],
 45 |       fileSlugStr: 'pagination',
 46 |       frontMatter: [Object],
 47 |       inputContent: '---\n' +
 48 |         'pagination:\n' +
 49 |         '  data: pages\n' +
 50 |         '  size: 1\n' +
 51 |         '  alias: p\n' +
 52 |         '  addAllPagesToCollections: true\n' +
 53 |         'permalink: "{{ p.title | slugify }}/"\n' +
 54 |         'tags:\n' +
 55 |         '  - page\n' +
 56 |         '---\n' +
 57 |         '\n' +
 58 |         '

{{ p.title }}

\n' + 59 | '\n', 60 | inputDir: 'src', 61 | inputPath: './src/pagination.liquid', 62 | isDryRun: false, 63 | isVerbose: true, 64 | linters: [], 65 | outputDir: 'www', 66 | outputFormat: 'fs', 67 | paginationData: [Object], 68 | parsed: [Object], 69 | plugins: {}, 70 | serverlessUrls: {}, 71 | skippedCount: 0, 72 | templateData: [TemplateData], 73 | transforms: [], 74 | wrapWithLayouts: true, 75 | writeCount: 0 76 | }, 77 | templateContent: [Getter/Setter], 78 | url: '/page-3/' 79 | }, 80 | { 81 | checkTemplateContent: true, 82 | data: { 83 | collections: [Object], 84 | eleventy: [Object], 85 | p: [Object], 86 | page: [Object], 87 | pages: [Array], 88 | pagination: [Object], 89 | permalink: '{{ p.title | slugify }}/', 90 | pkg: [Object], 91 | tags: [Array] 92 | }, 93 | date: 2022-02-14T00:00:00.000Z, 94 | filePathStem: '/pagination', 95 | fileSlug: 'pagination', 96 | inputPath: './src/pagination.liquid', 97 | outputPath: 'www/page-1/index.html', 98 | pageNumber: 0, 99 | template: Template { 100 | _config: [TemplateConfig], 101 | _extensionMap: [EleventyExtensionMap], 102 | _frontMatterDataCache: [Object], 103 | _logger: [ConsoleLogger], 104 | _stats: [Promise], 105 | _templateRender: [TemplateRender], 106 | _usePermalinkRoot: undefined, 107 | behavior: [TemplateBehavior], 108 | computedData: [ComputedData], 109 | dataCache: [Object], 110 | extraOutputSubdirectory: '', 111 | filePathStem: '/pagination', 112 | fileSlug: [TemplateFileSlug], 113 | fileSlugStr: 'pagination', 114 | frontMatter: [Object], 115 | inputContent: '---\n' + 116 | 'pagination:\n' + 117 | ' data: pages\n' + 118 | ' size: 1\n' + 119 | ' alias: p\n' + 120 | ' addAllPagesToCollections: true\n' + 121 | 'permalink: "{{ p.title | slugify }}/"\n' + 122 | 'tags:\n' + 123 | ' - page\n' + 124 | '---\n' + 125 | '\n' + 126 | '

{{ p.title }}

\n' + 127 | '\n', 128 | inputDir: 'src', 129 | inputPath: './src/pagination.liquid', 130 | isDryRun: false, 131 | isVerbose: true, 132 | linters: [], 133 | outputDir: 'www', 134 | outputFormat: 'fs', 135 | paginationData: [Object], 136 | parsed: [Object], 137 | plugins: {}, 138 | serverlessUrls: {}, 139 | skippedCount: 0, 140 | templateData: [TemplateData], 141 | transforms: [], 142 | wrapWithLayouts: true, 143 | writeCount: 0 144 | }, 145 | templateContent: [Getter/Setter], 146 | url: '/page-1/' 147 | }, 148 | { 149 | _templateContent: '\n' + 150 | '

\n' + 151 | '\n', 152 | checkTemplateContent: true, 153 | data: { 154 | collections: [Object], 155 | date: 2022-01-09T00:00:00.000Z, 156 | eleventy: [Object], 157 | page: [Object], 158 | pages: [Array], 159 | pkg: [Object], 160 | tags: [Array], 161 | title: 'Mock page' 162 | }, 163 | date: 2022-01-09T00:00:00.000Z, 164 | filePathStem: '/foo', 165 | fileSlug: 'foo', 166 | inputPath: './src/foo.liquid', 167 | outputPath: 'www/foo/index.html', 168 | template: Template { 169 | _config: [TemplateConfig], 170 | _extensionMap: [EleventyExtensionMap], 171 | _frontMatterDataCache: [Object], 172 | _logger: [ConsoleLogger], 173 | _templateRender: [TemplateRender], 174 | _usePermalinkRoot: undefined, 175 | behavior: [TemplateBehavior], 176 | computedData: [ComputedData], 177 | dataCache: [Object], 178 | extraOutputSubdirectory: '', 179 | filePathStem: '/foo', 180 | fileSlug: [TemplateFileSlug], 181 | fileSlugStr: 'foo', 182 | frontMatter: [Object], 183 | inputContent: '---\n' + 184 | 'title: Mock page\n' + 185 | 'date: 2022-01-09\n' + 186 | 'tags:\n' + 187 | ' - page\n' + 188 | '---\n' + 189 | '\n' + 190 | '

{{ p.title }}

\n' + 191 | '\n', 192 | inputDir: 'src', 193 | inputPath: './src/foo.liquid', 194 | isDryRun: false, 195 | isVerbose: true, 196 | linters: [], 197 | outputDir: 'www', 198 | outputFormat: 'fs', 199 | paginationData: {}, 200 | parsed: [Object], 201 | plugins: {}, 202 | serverlessUrls: null, 203 | skippedCount: 0, 204 | templateData: [TemplateData], 205 | transforms: [], 206 | wrapWithLayouts: true, 207 | writeCount: 0 208 | }, 209 | templateContent: [Getter/Setter], 210 | url: '/foo/' 211 | }, 212 | { 213 | checkTemplateContent: true, 214 | data: { 215 | collections: [Object], 216 | eleventy: [Object], 217 | p: [Object], 218 | page: [Object], 219 | pages: [Array], 220 | pagination: [Object], 221 | permalink: '{{ p.title | slugify }}/', 222 | pkg: [Object], 223 | tags: [Array] 224 | }, 225 | date: 2021-07-24T00:00:00.000Z, 226 | filePathStem: '/pagination', 227 | fileSlug: 'pagination', 228 | inputPath: './src/pagination.liquid', 229 | outputPath: 'www/page-2/index.html', 230 | pageNumber: 1, 231 | template: Template { 232 | _config: [TemplateConfig], 233 | _extensionMap: [EleventyExtensionMap], 234 | _frontMatterDataCache: [Object], 235 | _logger: [ConsoleLogger], 236 | _stats: [Promise], 237 | _templateRender: [TemplateRender], 238 | _usePermalinkRoot: undefined, 239 | behavior: [TemplateBehavior], 240 | computedData: [ComputedData], 241 | dataCache: [Object], 242 | extraOutputSubdirectory: '', 243 | filePathStem: '/pagination', 244 | fileSlug: [TemplateFileSlug], 245 | fileSlugStr: 'pagination', 246 | frontMatter: [Object], 247 | inputContent: '---\n' + 248 | 'pagination:\n' + 249 | ' data: pages\n' + 250 | ' size: 1\n' + 251 | ' alias: p\n' + 252 | ' addAllPagesToCollections: true\n' + 253 | 'permalink: "{{ p.title | slugify }}/"\n' + 254 | 'tags:\n' + 255 | ' - page\n' + 256 | '---\n' + 257 | '\n' + 258 | '

{{ p.title }}

\n' + 259 | '\n', 260 | inputDir: 'src', 261 | inputPath: './src/pagination.liquid', 262 | isDryRun: false, 263 | isVerbose: true, 264 | linters: [], 265 | outputDir: 'www', 266 | outputFormat: 'fs', 267 | paginationData: [Object], 268 | parsed: [Object], 269 | plugins: {}, 270 | serverlessUrls: {}, 271 | skippedCount: 0, 272 | templateData: [TemplateData], 273 | transforms: [], 274 | wrapWithLayouts: true, 275 | writeCount: 0 276 | }, 277 | templateContent: [Getter/Setter], 278 | url: '/page-2/' 279 | }, 280 | { 281 | checkTemplateContent: true, 282 | data: { 283 | collections: [Object], 284 | eleventy: [Object], 285 | p: [Object], 286 | page: [Object], 287 | pages: [Array], 288 | pagination: [Object], 289 | permalink: '{{ p.title | slugify }}/', 290 | pkg: [Object], 291 | tags: [Array] 292 | }, 293 | date: 2020-10-25T00:00:00.000Z, 294 | filePathStem: '/pagination', 295 | fileSlug: 'pagination', 296 | inputPath: './src/pagination.liquid', 297 | outputPath: 'www/page-4/index.html', 298 | pageNumber: 3, 299 | template: Template { 300 | _config: [TemplateConfig], 301 | _extensionMap: [EleventyExtensionMap], 302 | _frontMatterDataCache: [Object], 303 | _logger: [ConsoleLogger], 304 | _stats: [Promise], 305 | _templateRender: [TemplateRender], 306 | _usePermalinkRoot: undefined, 307 | behavior: [TemplateBehavior], 308 | computedData: [ComputedData], 309 | dataCache: [Object], 310 | extraOutputSubdirectory: '', 311 | filePathStem: '/pagination', 312 | fileSlug: [TemplateFileSlug], 313 | fileSlugStr: 'pagination', 314 | frontMatter: [Object], 315 | inputContent: '---\n' + 316 | 'pagination:\n' + 317 | ' data: pages\n' + 318 | ' size: 1\n' + 319 | ' alias: p\n' + 320 | ' addAllPagesToCollections: true\n' + 321 | 'permalink: "{{ p.title | slugify }}/"\n' + 322 | 'tags:\n' + 323 | ' - page\n' + 324 | '---\n' + 325 | '\n' + 326 | '

{{ p.title }}

\n' + 327 | '\n', 328 | inputDir: 'src', 329 | inputPath: './src/pagination.liquid', 330 | isDryRun: false, 331 | isVerbose: true, 332 | linters: [], 333 | outputDir: 'www', 334 | outputFormat: 'fs', 335 | paginationData: [Object], 336 | parsed: [Object], 337 | plugins: {}, 338 | serverlessUrls: {}, 339 | skippedCount: 0, 340 | templateData: [TemplateData], 341 | transforms: [], 342 | wrapWithLayouts: true, 343 | writeCount: 0 344 | }, 345 | templateContent: [Getter/Setter], 346 | url: '/page-4/' 347 | }, 348 | { 349 | checkTemplateContent: true, 350 | data: { 351 | collections: [Object], 352 | eleventy: [Object], 353 | p: [Object], 354 | page: [Object], 355 | pages: [Array], 356 | pagination: [Object], 357 | permalink: '{{ p.title | slugify }}/', 358 | pkg: [Object], 359 | tags: [Array] 360 | }, 361 | date: 2019-12-03T00:00:00.000Z, 362 | filePathStem: '/pagination', 363 | fileSlug: 'pagination', 364 | inputPath: './src/pagination.liquid', 365 | outputPath: 'www/page-5/index.html', 366 | pageNumber: 4, 367 | template: Template { 368 | _config: [TemplateConfig], 369 | _extensionMap: [EleventyExtensionMap], 370 | _frontMatterDataCache: [Object], 371 | _logger: [ConsoleLogger], 372 | _stats: [Promise], 373 | _templateRender: [TemplateRender], 374 | _usePermalinkRoot: undefined, 375 | behavior: [TemplateBehavior], 376 | computedData: [ComputedData], 377 | dataCache: [Object], 378 | extraOutputSubdirectory: '', 379 | filePathStem: '/pagination', 380 | fileSlug: [TemplateFileSlug], 381 | fileSlugStr: 'pagination', 382 | frontMatter: [Object], 383 | inputContent: '---\n' + 384 | 'pagination:\n' + 385 | ' data: pages\n' + 386 | ' size: 1\n' + 387 | ' alias: p\n' + 388 | ' addAllPagesToCollections: true\n' + 389 | 'permalink: "{{ p.title | slugify }}/"\n' + 390 | 'tags:\n' + 391 | ' - page\n' + 392 | '---\n' + 393 | '\n' + 394 | '

{{ p.title }}

\n' + 395 | '\n', 396 | inputDir: 'src', 397 | inputPath: './src/pagination.liquid', 398 | isDryRun: false, 399 | isVerbose: true, 400 | linters: [], 401 | outputDir: 'www', 402 | outputFormat: 'fs', 403 | paginationData: [Object], 404 | parsed: [Object], 405 | plugins: {}, 406 | serverlessUrls: {}, 407 | skippedCount: 0, 408 | templateData: [TemplateData], 409 | transforms: [], 410 | wrapWithLayouts: true, 411 | writeCount: 0 412 | }, 413 | templateContent: [Getter/Setter], 414 | url: '/page-5/' 415 | } 416 | ] 417 |
418 | --------------------------------------------------------------------------------