Skip to content

Commit 21db2ca

Browse files
committed
feat: TestResolverに画像のファイル出力を実装
1 parent cbcc3f2 commit 21db2ca

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

docs/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,6 @@ mod tests {
950950
let _ = std::fs::remove_dir_all("../assets/docs");
951951
// copy all files from ../assets/files to ../assets/docs
952952
std::fs::create_dir("../assets/docs").unwrap();
953-
for entry in std::fs::read_dir("../assets/files").unwrap() {
954-
let entry = entry.unwrap();
955-
let path = entry.path();
956-
let name = String::from(path.file_name().unwrap().to_str().unwrap());
957-
std::fs::copy(path, format!("../assets/docs/{}", name)).unwrap();
958-
}
959953
// convert all pages to html and generate example images to ../assets/docs
960954
let pages = provide(&TestResolver);
961955
// convert pages to JSON and save to ../assets/docs.json
@@ -998,7 +992,18 @@ mod tests {
998992
}
999993
}
1000994

1001-
fn image(&self, filename: &str, _: &[u8]) -> String {
995+
fn image(&self, filename: &str, data: &[u8]) -> String {
996+
// Set the output path
997+
let output_path = Path::new("../assets/docs").join(filename);
998+
999+
// Create parent directories if they don't exist
1000+
if let Some(parent) = output_path.parent() {
1001+
let _ = std::fs::create_dir_all(parent);
1002+
}
1003+
1004+
// Write the file
1005+
std::fs::write(&output_path, data).ok();
1006+
10021007
// return /assets/docs/<filename>
10031008
format!("/assets/docs/{}", filename)
10041009
}

0 commit comments

Comments
 (0)