- Commit
- 9d92ab75293a7921559f53f2408cb7cdf5bbd5a8
- Parent
- f343dc68255d7b6fadc151ba06141f12555a7cb9
- Author
- Pablo <pablo-escobar@riseup.net>
- Date
Fixed a bug
Fixed a bug regarding the creation of symlinks for the SVG thumbnails
Custum build of stapix for tikz.pablopie.xyz
Fixed a bug
Fixed a bug regarding the creation of symlinks for the SVG thumbnails
1 file changed, 17 insertions, 24 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | src/main.rs | 41 | 17 | 24 |
diff --git a/src/main.rs b/src/main.rs @@ -22,7 +22,7 @@ pub struct ThumbPath<'a>(pub &'a GalleryEntry); /// A wrapper for HTML-escaped strings pub struct Escaped<'a>(pub &'a str); -const TARGET_PATH: &str = "site"; +const TARGET_PATH: &str = "./site"; const PAGES_PATH: &str = "tikz"; const IMAGES_PATH: &str = "assets/images"; const THUMBS_PATH: &str = "assets/thumbs"; @@ -183,8 +183,7 @@ fn render_gallery(pics: Vec<GalleryEntry>) -> ExitCode { log!("Copying image files to the target directory..."); for pic in &pics { - let mut target_path = PathBuf::from("."); - target_path.push(TARGET_PATH); + let mut target_path = PathBuf::from(TARGET_PATH); target_path.push(IMAGES_PATH); target_path.push(&pic.file_name); @@ -253,8 +252,7 @@ fn render_gallery(pics: Vec<GalleryEntry>) -> ExitCode { } fn render_index(pics: &Vec<GalleryEntry>) -> io::Result<()> { - let mut path = PathBuf::from("."); - path.push(TARGET_PATH); + let mut path = PathBuf::from(TARGET_PATH); path.push("index.html"); let mut f = File::create(path)?; @@ -316,8 +314,7 @@ fn render_index(pics: &Vec<GalleryEntry>) -> io::Result<()> { } fn render_pic_page(pic: &GalleryEntry) -> io::Result<()> { - let mut path = PathBuf::from("."); - path.push(TARGET_PATH); + let mut path = PathBuf::from(TARGET_PATH); path.push(PAGES_PATH); path.push(pic.file_name.clone() + ".html"); @@ -534,32 +531,29 @@ fn render_thumbnail(pic: GalleryEntry) -> bool { } }, FileFormat::Svg => { - let mut thumb_abs_path = match env::current_dir() { + let mut src_path = PathBuf::from(TARGET_PATH); + src_path.push(IMAGES_PATH); + src_path.push(&pic.file_name); + + // Here we need the absolute path of the image to prevent issues + // with symlinks + let src_path = match fs::canonicalize(&src_path) { Ok(path) => path, Err(err) => { - // TODO: Check if the error was "File exists" (os error 17) - // In that case I suppose we should skip the rendering? errorln!( - "Failed to create symlink for {thumb:?}: Could not get current working directory: {err}", + "Failed to create symlink for {thumb:?}: Could not get absolute path of {src:?}: {err}", thumb = thumb_path, - err = err + src = src_path, + err = err, ); return false; } }; - thumb_abs_path.push(TARGET_PATH); - thumb_abs_path.push(IMAGES_PATH); - thumb_abs_path.push(&pic.file_name); - - let mut src_path = PathBuf::from("."); - src_path.push(TARGET_PATH); - src_path.push(IMAGES_PATH); - src_path.push(&pic.file_name); - if let Err(err) = unix::fs::symlink(&src_path, &thumb_abs_path) { + if let Err(err) = unix::fs::symlink(&src_path, &thumb_path) { errorln!( "Failed to create symlink {thumb:?} -> {src:?}: {err}", - thumb = thumb_abs_path, + thumb = thumb_path, src = src_path, err = err ); @@ -624,8 +618,7 @@ fn render_thumbnail(pic: GalleryEntry) -> bool { /// Helper to get the correct thumbnail path for a given entry fn thumb_path(pic: &GalleryEntry) -> PathBuf { - let mut result = PathBuf::from("."); - result.push(TARGET_PATH); + let mut result = PathBuf::from(TARGET_PATH); result.push(THUMBS_PATH); match pic.file_format {