Skip to content

Commit c40a671

Browse files
committed
1 of 2, documentation
1 parent ca23248 commit c40a671

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

conf/collections/taxes.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* a tax is defined as a collection of values, which hold a collection of pages
3+
* a tax may be 'tags', a value may be 'cats', and a page may be 'cats.md'
4+
*
5+
* a single tax can be nominated as a differentiator, which means pages of a different
6+
* tax will be grouped by the differentiator
7+
*
8+
* taxes: [tax,value]
9+
* taxesPaged: variation on taxes, see below
10+
* taxesDiffer: [tax,value, differentiator]
11+
* nestedTax: {tax: {value: [page]}}
12+
*
13+
* if eleventy supported double-layered pagination, all of this wouldn't be needed
14+
*/
15+
116
import { createRequire } from "node:module";
217
const require = createRequire(import.meta.url);
318
const collectionControl = require("../../src/_data/collectionsControl.json");
@@ -61,6 +76,13 @@ export function taxes(eleventyConfig) {
6176
return unique;
6277
});
6378

79+
/**
80+
* The goal of this is to paginate taxes with the following rules:
81+
* - if it isn't a differentiator, it should not be paginated
82+
* practically, this means only in: blog, garden, ... is paginated
83+
* - 30 items per page
84+
* - if the last page has less than 5 items, it should be merged with the previous page
85+
*/
6486
// biome-ignore lint/complexity/useArrowFunction: <explanation>
6587
eleventyConfig.addCollection("taxesPaged", function (collectionApi) {
6688
const taxAndValues = standard(collectionApi);
@@ -73,7 +95,10 @@ export function taxes(eleventyConfig) {
7395
const [taxonomy, value] = key.split("/./");
7496
let totalItems = taxAndValues[key];
7597
let pageNumber = 0;
76-
98+
let maxPage = Math.ceil(totalItems / maxItemsPerPage) - 1;
99+
if (totalItems % maxItemsPerPage < minItemsForLastPage) {
100+
maxPage--;
101+
}
77102
if (collectionControl[taxonomy].mode !== "differentiator") {
78103
paginatedResults.push({
79104
t: taxonomy,
@@ -82,6 +107,7 @@ export function taxes(eleventyConfig) {
82107
itemsInPage: totalItems,
83108
hasNext: false,
84109
hasPrev: false,
110+
maxPage,
85111
});
86112
continue;
87113
}
@@ -103,6 +129,7 @@ export function taxes(eleventyConfig) {
103129
itemsInPage: itemsInPage,
104130
hasNext: totalItems > itemsInPage,
105131
hasPrev: pageNumber > 0,
132+
maxPage,
106133
});
107134

108135
totalItems -= itemsInPage;

src/styles/main.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,16 @@ label {
255255
font-weight: bold;
256256
}
257257

258-
.padded {
258+
.pagination {
259259
border-radius: $radius;
260260
border: 2px solid var(--border);
261261
padding: $p1 $p2;
262+
view-transition-name: pagination;
263+
@media screen and (max-width: $mobileWidth) {
264+
ul {
265+
justify-content: space-between;
266+
}
267+
}
262268
}
263269

264270
// (Media Queries)

src/taxValues.vto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ eleventyComputed:
7373
{{ /for }}
7474
</div>
7575
{{ if cur.hasNext || cur.hasPrev }}
76-
<dl class="kv padded">
77-
<dt>Page {{cur.n+1}}</dt>
76+
<dl class="kv pagination">
77+
<dt>Page {{cur.n+1}} <i>of</i> {{cur.maxPage+1}}</dt>
7878
<dd>
7979
<ul>
8080
{{ if cur.hasPrev }}
8181
<li>
82-
<a href="/{{collectionsControl[cur.t]?.single || cur.t |> slugshive}}/{{ cur.v |> slugshive }}{{cur.n > 1 ? `/${cur.n-1}` : ""}}.html">&#9753; Prev</a>
82+
<a href="/{{collectionsControl[cur.t]?.single || cur.t |> slugshive}}/{{ cur.v |> slugshive }}{{cur.n > 1 ? `/${cur.n}` : ""}}">&#9753; Prev</a>
8383
</li>
8484
{{ /if }}
8585
{{ if cur.hasNext }}
8686
<li>
87-
<a href="/{{collectionsControl[cur.t]?.single || cur.t |> slugshive}}/{{ cur.v |> slugshive }}/{{cur.n+2}}.html">Next &#10087;</a>
87+
<a href="/{{collectionsControl[cur.t]?.single || cur.t |> slugshive}}/{{ cur.v |> slugshive }}/{{cur.n+2}}">Next &#10087;</a>
8888
</li>
8989
{{ /if }}
9090
</ul>

0 commit comments

Comments
 (0)