Include chapters with no headers in the search index
This commit is contained in:
parent
48b5e52f62
commit
2a8af1c21d
|
@ -165,7 +165,12 @@ fn render_item(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !heading.is_empty() {
|
if !body.is_empty() || !heading.is_empty() {
|
||||||
|
if heading.is_empty() {
|
||||||
|
if let Some(chapter) = breadcrumbs.first() {
|
||||||
|
heading = chapter.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
// Make sure the last section is added to the index
|
// Make sure the last section is added to the index
|
||||||
add_doc(
|
add_doc(
|
||||||
index,
|
index,
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
- [Recursive](first/recursive.md)
|
- [Recursive](first/recursive.md)
|
||||||
- [Markdown](first/markdown.md)
|
- [Markdown](first/markdown.md)
|
||||||
- [Unicode](first/unicode.md)
|
- [Unicode](first/unicode.md)
|
||||||
|
- [No Headers](first/no-headers.md)
|
||||||
- [Second Chapter](second.md)
|
- [Second Chapter](second.md)
|
||||||
- [Nested Chapter](second/nested.md)
|
- [Nested Chapter](second/nested.md)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Capybara capybara capybara.
|
||||||
|
|
||||||
|
Capybara capybara capybara.
|
|
@ -34,6 +34,7 @@ const TOC_SECOND_LEVEL: &[&str] = &[
|
||||||
"1.3. Recursive",
|
"1.3. Recursive",
|
||||||
"1.4. Markdown",
|
"1.4. Markdown",
|
||||||
"1.5. Unicode",
|
"1.5. Unicode",
|
||||||
|
"1.6. No Headers",
|
||||||
"2.1. Nested Chapter",
|
"2.1. Nested Chapter",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -631,6 +632,7 @@ mod search {
|
||||||
let introduction = get_doc_ref("intro.html#introduction");
|
let introduction = get_doc_ref("intro.html#introduction");
|
||||||
let some_section = get_doc_ref("first/index.html#some-section");
|
let some_section = get_doc_ref("first/index.html#some-section");
|
||||||
let summary = get_doc_ref("first/includes.html#summary");
|
let summary = get_doc_ref("first/includes.html#summary");
|
||||||
|
let no_headers = get_doc_ref("first/no-headers.html");
|
||||||
let conclusion = get_doc_ref("conclusion.html#conclusion");
|
let conclusion = get_doc_ref("conclusion.html#conclusion");
|
||||||
|
|
||||||
let bodyidx = &index["index"]["index"]["body"]["root"];
|
let bodyidx = &index["index"]["index"]["body"]["root"];
|
||||||
|
@ -644,13 +646,21 @@ mod search {
|
||||||
assert_eq!(docs[&some_section]["body"], "");
|
assert_eq!(docs[&some_section]["body"], "");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
docs[&summary]["body"],
|
docs[&summary]["body"],
|
||||||
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode Second Chapter Nested Chapter Conclusion"
|
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode No Headers Second Chapter Nested Chapter Conclusion"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
docs[&summary]["breadcrumbs"],
|
docs[&summary]["breadcrumbs"],
|
||||||
"First Chapter » Includes » Summary"
|
"First Chapter » Includes » Summary"
|
||||||
);
|
);
|
||||||
assert_eq!(docs[&conclusion]["body"], "I put <HTML> in here!");
|
assert_eq!(docs[&conclusion]["body"], "I put <HTML> in here!");
|
||||||
|
assert_eq!(
|
||||||
|
docs[&no_headers]["breadcrumbs"],
|
||||||
|
"First Chapter » No Headers"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
docs[&no_headers]["body"],
|
||||||
|
"Capybara capybara capybara. Capybara capybara capybara."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting this to `true` may cause issues with `cargo watch`,
|
// Setting this to `true` may cause issues with `cargo watch`,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue