This returns a new tree that groups the original keys and values into “pages”: fixed-size sets of items that are no bigger than count
. A typical use for this is breaking a long list of blog posts, search results, etc., into multiple web pages.
$ cat countries.yaml
- name: France
flag: 🇫🇷
- name: Greece
flag: 🇬🇷
- name: Italy
flag: 🇮🇹
- name: Portugal
flag: 🇵🇹
- name: Spain
flag: 🇪🇸
The above set of countries can be broken into pages of (up to) 3 items each:
$ ori @paginate countries.yaml, 3
"1":
items:
- name: France
flag: 🇫🇷
- name: Greece
flag: 🇬🇷
- name: Italy
flag: 🇮🇹
nextPage: 2
pageCount: 2
pageNumber: 1
previousPage: null
"2":
items:
"3":
name: Portugal
flag: 🇵🇹
"4":
name: Spain
flag: 🇪🇸
nextPage: null
pageCount: 2
pageNumber: 2
previousPage: 1
Each page includes:
items
: the items assigned to this pagenextPage
: the number of the next page, ornull
for the last pagepageCount
: the total number of pagespageNumber
: the number assign to this page, starting with 1previousPage
: the number of the previous page, ornull
for the first page
See also @addNextPrevious, which cross-links a series of items without grouping them into pages.