Skip to content

Commit d4685f7

Browse files
committed
feat: add cyclic wrap to content modal
1 parent 51744d2 commit d4685f7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

core/mock_data.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010
def _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
]

0 commit comments

Comments
 (0)