Skip to content

Commit 13a5d80

Browse files
committed
Fix "next" navigation on index.html (take 2).
1 parent a873d46 commit 13a5d80

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl HtmlHandlebars {
8585
if ctx.is_index {
8686
ctx.data.insert("path".to_owned(), json!("index.md"));
8787
ctx.data.insert("path_to_root".to_owned(), json!(""));
88+
ctx.data.insert("is_index".to_owned(), json!("true"));
8889
let rendered_index = ctx.handlebars.render("index", &ctx.data)?;
8990
let rendered_index = self.post_process(rendered_index, &ctx.html_config.playpen);
9091
debug!("Creating index.html from {}", path);

src/renderer/html_handlebars/helpers/navigation.rs

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ fn find_chapter(
6363
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
6464
.replace("\"", "");
6565

66+
if !rc.evaluate(ctx, "@root/is_index")?.is_missing() {
67+
// Special case for index.md which may be a synthetic page.
68+
// Target::find won't match because there is no page with the path
69+
// "index.md" (unless there really is an index.md in SUMMARY.md).
70+
match target {
71+
Target::Previous => return Ok(None),
72+
Target::Next => match chapters.iter().skip(1).next() {
73+
Some(chapter) => return Ok(Some(chapter.clone())),
74+
None => return Ok(None),
75+
},
76+
}
77+
}
78+
6679
let mut previous: Option<StringMap> = None;
6780

6881
debug!("Search for chapter");

0 commit comments

Comments
 (0)