Skip to content

Commit 7821bd2

Browse files
committed
fix(history): enable translated content history
1 parent 560f198 commit 7821bd2

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

Diff for: crates/rari-cli/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn main() -> Result<(), Error> {
316316
Commands::GitHistory => {
317317
println!("Gathering history 📜");
318318
let start = std::time::Instant::now();
319-
gather_history();
319+
gather_history()?;
320320
println!("Took: {:?}", start.elapsed());
321321
}
322322
Commands::Popularities => {

Diff for: crates/rari-cli/serve.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ struct AppError(anyhow::Error);
2626

2727
impl IntoResponse for AppError {
2828
fn into_response(self) -> Response {
29-
(
30-
StatusCode::INTERNAL_SERVER_ERROR,
31-
error!("🤷‍♂️: {}", self.0),
32-
)
33-
.into_response()
29+
(StatusCode::INTERNAL_SERVER_ERROR, error!("🤷‍♂️: {}", self.0)).into_response()
3430
}
3531
}
3632
impl<E> From<E> for AppError

Diff for: crates/rari-doc/src/pages/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ fn build_doc(doc: &Doc) -> Result<BuiltDocy, DocError> {
248248
},
249249
history.map(|entry| entry.hash.as_str()).unwrap_or_default()
250250
);
251-
252251
let popularity = popularities().popularities.get(doc.url()).cloned();
253252
let other_translations = get_translations_for(doc.slug(), doc.locale())
254253
.into_iter()

Diff for: crates/rari-tools/src/history.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
use std::collections::BTreeMap;
22
use std::fs::File;
33
use std::io::BufWriter;
4-
use std::path::PathBuf;
4+
use std::path::{Path, PathBuf};
55
use std::process::Command;
6+
use std::thread::spawn;
67

7-
use rari_types::globals::content_root;
8+
use rari_types::globals::{content_root, content_translated_root};
89
use rari_types::HistoryEntry;
910

10-
pub fn gather_history() -> BTreeMap<PathBuf, HistoryEntry> {
11-
modification_times()
11+
use crate::error::ToolError;
12+
13+
pub fn gather_history() -> Result<(), ToolError> {
14+
let hanlde = content_translated_root().map(|translated_root| {
15+
spawn(|| {
16+
modification_times(translated_root).unwrap();
17+
})
18+
});
19+
modification_times(content_root())?;
20+
if let Some(handle) = hanlde {
21+
handle.join().expect("Unable to join history thread.");
22+
}
23+
Ok(())
1224
}
1325

14-
fn modification_times(//path: &Path,
15-
) -> BTreeMap<PathBuf, HistoryEntry> {
16-
let path = content_root();
26+
fn modification_times(path: &Path) -> Result<(), ToolError> {
1727
let output = Command::new("git")
1828
.args(["rev-parse", "--show-toplevel"])
1929
.current_dir(path)
@@ -82,10 +92,10 @@ fn modification_times(//path: &Path,
8292
})
8393
.collect::<BTreeMap<PathBuf, HistoryEntry>>();
8494

85-
let out_file = path.join("en-US").join("_history.json");
95+
let out_file = path.join("_git_history.json");
8696
let file = File::create(out_file).unwrap();
8797
let buffed = BufWriter::new(file);
8898

8999
serde_json::to_writer_pretty(buffed, &history).unwrap();
90-
history
100+
Ok(())
91101
}

Diff for: crates/rari-types/src/globals.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,30 @@ pub fn json_svg_data_lookup() -> &'static JsonSVGDataLookup {
135135
}
136136

137137
pub static GIT_HISTORY: LazyLock<HashMap<PathBuf, HistoryEntry>> = LazyLock::new(|| {
138-
let f = content_root().join("en-US").join("_history.json");
139-
if let Ok(json_str) = fs::read_to_string(f) {
138+
let f = content_root().join("_git_history.json");
139+
let mut map = if let Ok(json_str) = fs::read_to_string(f) {
140140
serde_json::from_str(&json_str).expect("unable to parse l10n json")
141141
} else {
142142
HashMap::new()
143+
};
144+
if let Some(translated_root) = content_translated_root() {
145+
let f = translated_root.join("_git_history.json");
146+
if let Ok(json_str) = fs::read_to_string(f) {
147+
let translated: HashMap<PathBuf, HistoryEntry> =
148+
serde_json::from_str(&json_str).expect("unable to parse l10n json");
149+
map.extend(translated);
150+
};
143151
}
152+
map
144153
});
145154
pub fn git_history() -> &'static HashMap<PathBuf, HistoryEntry> {
146155
&GIT_HISTORY
147156
}
148157

149158
pub static POPULARITIES: LazyLock<Popularities> = LazyLock::new(|| {
150-
let f = content_root().join("en-US").join("popularities.json");
159+
let f = content_root()
160+
.join(Locale::EnUs.as_folder_str())
161+
.join("popularities.json");
151162
if let Ok(json_str) = fs::read_to_string(f) {
152163
serde_json::from_str(&json_str).expect("unable to parse l10n json")
153164
} else {

0 commit comments

Comments
 (0)