Skip to content

Commit 9634798

Browse files
authored
Merge pull request #1637 from notriddle/no-headers
Include chapters with no headers in the search index
2 parents 48b5e52 + 2a8af1c commit 9634798

File tree

5 files changed

+490
-255
lines changed

5 files changed

+490
-255
lines changed

src/renderer/html_handlebars/search.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ fn render_item(
165165
}
166166
}
167167

168-
if !heading.is_empty() {
168+
if !body.is_empty() || !heading.is_empty() {
169+
if heading.is_empty() {
170+
if let Some(chapter) = breadcrumbs.first() {
171+
heading = chapter.clone();
172+
}
173+
}
169174
// Make sure the last section is added to the index
170175
add_doc(
171176
index,

tests/dummy_book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Recursive](first/recursive.md)
1313
- [Markdown](first/markdown.md)
1414
- [Unicode](first/unicode.md)
15+
- [No Headers](first/no-headers.md)
1516
- [Second Chapter](second.md)
1617
- [Nested Chapter](second/nested.md)
1718

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Capybara capybara capybara.
2+
3+
Capybara capybara capybara.

tests/rendered_output.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const TOC_SECOND_LEVEL: &[&str] = &[
3434
"1.3. Recursive",
3535
"1.4. Markdown",
3636
"1.5. Unicode",
37+
"1.6. No Headers",
3738
"2.1. Nested Chapter",
3839
];
3940

@@ -631,6 +632,7 @@ mod search {
631632
let introduction = get_doc_ref("intro.html#introduction");
632633
let some_section = get_doc_ref("first/index.html#some-section");
633634
let summary = get_doc_ref("first/includes.html#summary");
635+
let no_headers = get_doc_ref("first/no-headers.html");
634636
let conclusion = get_doc_ref("conclusion.html#conclusion");
635637

636638
let bodyidx = &index["index"]["index"]["body"]["root"];
@@ -644,13 +646,21 @@ mod search {
644646
assert_eq!(docs[&some_section]["body"], "");
645647
assert_eq!(
646648
docs[&summary]["body"],
647-
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode Second Chapter Nested Chapter Conclusion"
649+
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode No Headers Second Chapter Nested Chapter Conclusion"
648650
);
649651
assert_eq!(
650652
docs[&summary]["breadcrumbs"],
651653
"First Chapter » Includes » Summary"
652654
);
653655
assert_eq!(docs[&conclusion]["body"], "I put <HTML> in here!");
656+
assert_eq!(
657+
docs[&no_headers]["breadcrumbs"],
658+
"First Chapter » No Headers"
659+
);
660+
assert_eq!(
661+
docs[&no_headers]["body"],
662+
"Capybara capybara capybara. Capybara capybara capybara."
663+
);
654664
}
655665

656666
// Setting this to `true` may cause issues with `cargo watch`,

0 commit comments

Comments
 (0)