Skip to content

Commit c08508f

Browse files
committed
fix(page): Don't panic on empty all
Fixes #1239
1 parent a9b8587 commit c08508f

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

Diff for: src/pagination/all.rs

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ pub(crate) fn create_all_paginators(
1414
// f32 used here in order to not lose information to ceil the result,
1515
// otherwise we can lose an index
1616
let total_indexes = (total_pages as f32 / config.per_page as f32).ceil() as usize;
17+
18+
if total_pages == 0 {
19+
return Ok(vec![paginator::create_paginator(
20+
0,
21+
total_indexes,
22+
total_pages,
23+
config,
24+
doc,
25+
&[],
26+
index_title,
27+
)?]);
28+
}
29+
1730
let paginators: Result<Vec<_>> = all_posts
1831
.chunks(config.per_page as usize)
1932
.enumerate()

Diff for: tests/cmd/pagination_all_empty.in/_dest/index.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>test</title>
5+
</head>
6+
<body>
7+
<h1></h1>
8+
9+
This is my Index page!
10+
11+
12+
13+
14+
<div>
15+
16+
17+
18+
<span>1 / 0</span>
19+
</div>
20+
21+
</body>
22+
</html>
23+

Diff for: tests/cmd/pagination_all_empty.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
```console
22
$ cobalt -v build --destination _dest
3-
? interrupted
43
DEBUG: Using config file `./_cobalt.yml`
54
Building from `.` into `[CWD]/_dest`
65
DEBUG: glob converted to regex: Glob { glob: "**/.*", re: "(?-u)^(?:/?|.*/)//.[^/]*$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true, empty_alternates: false }, tokens: Tokens([RecursivePrefix, Literal('.'), ZeroOrMore]) }
@@ -11,9 +10,6 @@ DEBUG: glob converted to regex: Glob { glob: "**/.*", re: "(?-u)^(?:/?|.*/)//.[^
1110
DEBUG: glob converted to regex: Glob { glob: "**/_*", re: "(?-u)^(?:/?|.*/)_[^/]*$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true, empty_alternates: false }, tokens: Tokens([RecursivePrefix, Literal('_'), ZeroOrMore]) }
1211
DEBUG: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 2 regexes
1312
DEBUG: Loading snippets from `./_includes`
14-
15-
thread 'main' panicked at src/cobalt.rs:251:18:
16-
We detected pagination enabled but we have no paginator
17-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
13+
Build successful
1814

1915
```

0 commit comments

Comments
 (0)