diff options
| author | Fuwn <[email protected]> | 2022-04-22 00:28:08 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-22 00:28:08 -0700 |
| commit | 06a868e62c986844ec7e0311ce4838477097180b (patch) | |
| tree | 7e0e6a98fe6e60d1e30fe821808a93553b3351fe /src/modules | |
| parent | feat(footer): add search and sitemap (diff) | |
| download | locus-06a868e62c986844ec7e0311ce4838477097180b.tar.xz locus-06a868e62c986844ec7e0311ce4838477097180b.zip | |
feat(search): add context to search previews
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/search.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/modules/search.rs b/src/modules/search.rs index 06f6152..56828b0 100644 --- a/src/modules/search.rs +++ b/src/modules/search.rs @@ -90,11 +90,15 @@ pub fn module(router: &mut windmark::Router) { lines.next().map_or_else( || "".to_string(), |first_line| { + let mut context_lines = lines.skip_while(|l| { + !l.to_lowercase().contains(&query.0.to_string()) + }); + format!( "\n> ... {}\n> {}\n> {} ...", first_line, - lines.next().unwrap_or(""), - lines.next().unwrap_or("") + context_lines.next().unwrap_or(""), + context_lines.next().unwrap_or("") ) }, ) |