File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010def _with_carousel_nav (items , slug_key = "title" ):
1111 """Annotate each item with `slug`, `prev_url`, `next_url` for in-page
12- carousel/modal navigation. `prev_url` is empty on the first item and
13- `next_url` is empty on the last.
12+ carousel/modal navigation. Navigation wraps cyclically: the first item's
13+ `prev_url` points to the last item, and the last item's `next_url`
14+ points to the first.
1415 """
1516 slugs = [slugify (item [slug_key ]) for item in items ]
17+ n = len (items )
1618 return [
1719 {
1820 ** item ,
1921 "slug" : slugs [i ],
20- "prev_url" : f"#{ slugs [i - 1 ] } " if i > 0 else " " ,
21- "next_url" : f"#{ slugs [i + 1 ] } " if i < len ( slugs ) - 1 else " " ,
22+ "prev_url" : f"#{ slugs [( i - 1 ) % n ] } " ,
23+ "next_url" : f"#{ slugs [( i + 1 ) % n ] } " ,
2224 }
2325 for i , item in enumerate (items )
2426 ]
You can’t perform that action at this time.
0 commit comments