diff --git a/crates/rari-cli/main.rs b/crates/rari-cli/main.rs index 8ced3ce..a507f8c 100644 --- a/crates/rari-cli/main.rs +++ b/crates/rari-cli/main.rs @@ -316,7 +316,7 @@ fn main() -> Result<(), Error> { Commands::GitHistory => { println!("Gathering history 📜"); let start = std::time::Instant::now(); - gather_history(); + gather_history()?; println!("Took: {:?}", start.elapsed()); } Commands::Popularities => { diff --git a/crates/rari-cli/serve.rs b/crates/rari-cli/serve.rs index eb2faa2..3c878e7 100644 --- a/crates/rari-cli/serve.rs +++ b/crates/rari-cli/serve.rs @@ -26,11 +26,7 @@ struct AppError(anyhow::Error); impl IntoResponse for AppError { fn into_response(self) -> Response { - ( - StatusCode::INTERNAL_SERVER_ERROR, - error!("🤷‍♂️: {}", self.0), - ) - .into_response() + (StatusCode::INTERNAL_SERVER_ERROR, error!("🤷‍♂️: {}", self.0)).into_response() } } impl From for AppError diff --git a/crates/rari-doc/src/pages/build.rs b/crates/rari-doc/src/pages/build.rs index f9fc74b..816d8df 100644 --- a/crates/rari-doc/src/pages/build.rs +++ b/crates/rari-doc/src/pages/build.rs @@ -248,7 +248,6 @@ fn build_doc(doc: &Doc) -> Result { }, history.map(|entry| entry.hash.as_str()).unwrap_or_default() ); - let popularity = popularities().popularities.get(doc.url()).cloned(); let other_translations = get_translations_for(doc.slug(), doc.locale()) .into_iter() diff --git a/crates/rari-tools/src/history.rs b/crates/rari-tools/src/history.rs index 8852e6f..8cd4f13 100644 --- a/crates/rari-tools/src/history.rs +++ b/crates/rari-tools/src/history.rs @@ -1,19 +1,29 @@ use std::collections::BTreeMap; use std::fs::File; use std::io::BufWriter; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; +use std::thread::spawn; -use rari_types::globals::content_root; +use rari_types::globals::{content_root, content_translated_root}; use rari_types::HistoryEntry; -pub fn gather_history() -> BTreeMap { - modification_times() +use crate::error::ToolError; + +pub fn gather_history() -> Result<(), ToolError> { + let hanlde = content_translated_root().map(|translated_root| { + spawn(|| { + modification_times(translated_root).unwrap(); + }) + }); + modification_times(content_root())?; + if let Some(handle) = hanlde { + handle.join().expect("Unable to join history thread."); + } + Ok(()) } -fn modification_times(//path: &Path, -) -> BTreeMap { - let path = content_root(); +fn modification_times(path: &Path) -> Result<(), ToolError> { let output = Command::new("git") .args(["rev-parse", "--show-toplevel"]) .current_dir(path) @@ -82,10 +92,10 @@ fn modification_times(//path: &Path, }) .collect::>(); - let out_file = path.join("en-US").join("_history.json"); + let out_file = path.join("_git_history.json"); let file = File::create(out_file).unwrap(); let buffed = BufWriter::new(file); serde_json::to_writer_pretty(buffed, &history).unwrap(); - history + Ok(()) } diff --git a/crates/rari-types/src/globals.rs b/crates/rari-types/src/globals.rs index 66c1f22..abdaa18 100644 --- a/crates/rari-types/src/globals.rs +++ b/crates/rari-types/src/globals.rs @@ -135,19 +135,30 @@ pub fn json_svg_data_lookup() -> &'static JsonSVGDataLookup { } pub static GIT_HISTORY: LazyLock> = LazyLock::new(|| { - let f = content_root().join("en-US").join("_history.json"); - if let Ok(json_str) = fs::read_to_string(f) { + let f = content_root().join("_git_history.json"); + let mut map = if let Ok(json_str) = fs::read_to_string(f) { serde_json::from_str(&json_str).expect("unable to parse l10n json") } else { HashMap::new() + }; + if let Some(translated_root) = content_translated_root() { + let f = translated_root.join("_git_history.json"); + if let Ok(json_str) = fs::read_to_string(f) { + let translated: HashMap = + serde_json::from_str(&json_str).expect("unable to parse l10n json"); + map.extend(translated); + }; } + map }); pub fn git_history() -> &'static HashMap { &GIT_HISTORY } pub static POPULARITIES: LazyLock = LazyLock::new(|| { - let f = content_root().join("en-US").join("popularities.json"); + let f = content_root() + .join(Locale::EnUs.as_folder_str()) + .join("popularities.json"); if let Ok(json_str) = fs::read_to_string(f) { serde_json::from_str(&json_str).expect("unable to parse l10n json") } else {