Skip to content

Commit 95f589e

Browse files
committed
ensure files in search index are sorted to avoid spurious diffs
1 parent b84145e commit 95f589e

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

search_index.postcard

368 Bytes
Binary file not shown.

src/main.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn git_get_articles_stats() -> Vec<GitStat> {
370370
let output_str = String::from_utf8_lossy(&output.stdout);
371371
let mut lines = output_str.lines().peekable();
372372

373-
let mut res: HashMap<String, GitStat> = HashMap::with_capacity(256);
373+
let mut res: BTreeMap<String, GitStat> = BTreeMap::new();
374374

375375
loop {
376376
// End?
@@ -1241,6 +1241,12 @@ fn generate_all(cache: &mut HashMap<String, Article>) {
12411241
let html_footer = fs::read("footer.html").unwrap();
12421242

12431243
let git_stats = git_get_articles_stats();
1244+
assert!(
1245+
git_stats.is_sorted_by(
1246+
|a, b| a.path_from_git_root.cmp(&b.path_from_git_root) != Ordering::Greater
1247+
)
1248+
);
1249+
12441250
let mut search_index = SearchIndex::new();
12451251
let mut articles: Vec<Article> = git_stats
12461252
.into_iter()
@@ -1326,41 +1332,41 @@ fn main() {
13261332
EventKind::Access(_access_kind) => {}
13271333
EventKind::Modify(ModifyKind::Metadata(_)) => {
13281334
dbg!(&event);
1329-
for path in event.paths {
1330-
if path.file_stem() == Some(&header)
1331-
|| path.file_stem() == Some(&footer)
1332-
{
1333-
println!(
1334-
"🔄 header/footer changed, rebuilding & reloading all files"
1335-
);
1336-
// let mut cache = cache.lock().unwrap();
1337-
// cache.clear();
1338-
// generate_all(&mut cache);
1339-
// websocket.send_text("").unwrap();
1340-
}
1341-
if path_str.ends_with(".js")
1342-
|| path_str.ends_with(".css")
1343-
|| path_str.ends_with(".svg")
1344-
|| path_str.ends_with(".png")
1345-
|| path_str.ends_with(".webm")
1346-
|| path_str.ends_with(".mp4")
1347-
|| path_str.ends_with(".jpeg")
1348-
|| path_str.ends_with(".ico")
1349-
|| path_str.ends_with(".gif")
1350-
{
1351-
println!("🔄 asset changed, reloading all files: {}", path_str);
1352-
// websocket.send_text("").unwrap();
1353-
}
1354-
if path.extension() == Some(&md_ext) {
1355-
println!(
1356-
"🔄 md file changed, rebuilding & reloading it: {}",
1357-
path_str
1358-
);
1359-
// let mut cache = cache.lock().unwrap();
1360-
// generate_all(&mut cache);
1361-
// websocket.send_text(&file_path_str).unwrap();
1362-
}
1363-
}
1335+
//for path in event.paths {
1336+
// if path.file_stem() == Some(&header)
1337+
// || path.file_stem() == Some(&footer)
1338+
// {
1339+
// println!(
1340+
// "🔄 header/footer changed, rebuilding & reloading all files"
1341+
// );
1342+
// // let mut cache = cache.lock().unwrap();
1343+
// // cache.clear();
1344+
// // generate_all(&mut cache);
1345+
// // websocket.send_text("").unwrap();
1346+
// }
1347+
// if path_str.ends_with(".js")
1348+
// || path_str.ends_with(".css")
1349+
// || path_str.ends_with(".svg")
1350+
// || path_str.ends_with(".png")
1351+
// || path_str.ends_with(".webm")
1352+
// || path_str.ends_with(".mp4")
1353+
// || path_str.ends_with(".jpeg")
1354+
// || path_str.ends_with(".ico")
1355+
// || path_str.ends_with(".gif")
1356+
// {
1357+
// println!("🔄 asset changed, reloading all files: {}", path_str);
1358+
// // websocket.send_text("").unwrap();
1359+
// }
1360+
// if path.extension() == Some(&md_ext) {
1361+
// println!(
1362+
// "🔄 md file changed, rebuilding & reloading it: {}",
1363+
// path_str
1364+
// );
1365+
// // let mut cache = cache.lock().unwrap();
1366+
// // generate_all(&mut cache);
1367+
// // websocket.send_text(&file_path_str).unwrap();
1368+
// }
1369+
//}
13641370
}
13651371
EventKind::Modify(_) => {}
13661372
EventKind::Remove(_remove_kind) => todo!(),

0 commit comments

Comments
 (0)