@addNextPrevious(treelike)

This returns a new tree that extends the values in the given tree with nextKey and previousKey properties. These properties will indicate the keys of the next and previous entries in the tree. This information can then be used to, for example, add links below a blog post that take the reader to the next or previous post.

Example application of @addNextPrevious to a tree of strings:

$ cat letters.yaml
a: The letter A
b: The letter B
c: The letter C
$ ori @addNextPrevious letters.yaml
a:
  "@text": The letter A
  nextKey: b
b:
  "@text": The letter B
  nextKey: c
  previousKey: a
c:
  "@text": The letter C
  previousKey: b
g a The letter A ->a a b The letter B ->b b c The letter C ->c c
g a ->a a b ->b b c ->c c a/@text The letter A a->a/@text @text a/nextKey b a->a/nextKey nextKey b/@text The letter B b->b/@text @text b/nextKey c b->b/nextKey nextKey b/previousKey a b->b/previousKey previousKey c/@text The letter C c->c/@text @text c/previousKey b c->c/previousKey previousKey
Input tree
Result of @addNextPrevious

If the values in the given tree aren’t plain objects, they will be transformed to plain objects as follows:

  • A value which is an AsyncTree will be resolved to a plain object.
  • A string value will become a plain object with a @text property containing the string.
  • Any other scalar value will become a plain object with a @data property containing the scalar value.

See also @paginate, which groups a set of items into fixed-size pages.