Use pattern search-index*.js for index files

Previously, we always tried to load the search index from the
search-index.js file.  But rustdoc may add a suffix to the file name, so
with withs patch, we use the first file that matches the pattern
search-index*.json.  This makes it possible to use rusty-man with the
documentation installed by rustup.
This commit is contained in:
Robin Krahl 2020-07-20 13:47:35 +02:00
parent d0c73d2523
commit 58929bc98b
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8

View File

@ -3,6 +3,7 @@
//! Handles documentation sources, for example local directories.
use std::fs;
use std::path;
use anyhow::anyhow;
@ -43,12 +44,18 @@ impl Source for DirSource {
}
fn load_index(&self) -> anyhow::Result<Option<index::Index>> {
let index_path = self.path.join("search-index.js");
if index_path.is_file() {
index::Index::load(&index_path)
} else {
Ok(None)
// use the first file that matches the pattern search-index*.js
for entry in fs::read_dir(&self.path)? {
let entry = entry?;
if entry.file_type()?.is_file() {
if let Some(s) = entry.file_name().to_str() {
if s.starts_with("search-index") && s.ends_with(".js") {
return index::Index::load(&entry.path());
}
}
}
}
Ok(None)
}
}