diff --git a/src/nex.rs b/src/nex.rs index 6f90a95..1dbb36b 100644 --- a/src/nex.rs +++ b/src/nex.rs @@ -130,6 +130,14 @@ impl Nex { fs::write(&s, updated.unwrap_or(published).to_string())? } else { if let Some(ref mut i) = index { + if let Some(ref a) = attachments { + for (n, (_, _, source)) in a.iter().enumerate() { + match source { + Source::File(f) => i.push(attachment::filepath(&d, f, n)), + _ => continue, + } + } + } i.extend([d, f, p, s]); } return Ok(Sync { @@ -162,22 +170,19 @@ impl Nex { match source { Source::Url(url) => url, Source::File(from) => { - let mut to = PathBuf::from(&d); - let f = format!( - "{}{}", - n + 1, - from.extension() - .map(|e| format!(".{}", e.to_string_lossy())) - .unwrap_or_default(), + let to = attachment::filepath(&d, &from, n); + let uri = format!( + "{}/{}", + d.file_name().unwrap().to_string_lossy(), + to.file_name().unwrap().to_string_lossy() ); - to.push(&f); if !to.exists() { self.attachment.sync(&from, &to).unwrap() } if let Some(ref mut i) = index { i.push(to); } - format!("{}/{f}", d.file_name().unwrap().to_string_lossy()) + uri } } )); diff --git a/src/nex/attachment.rs b/src/nex/attachment.rs index f0f8dfa..ece2a92 100644 --- a/src/nex/attachment.rs +++ b/src/nex/attachment.rs @@ -1,5 +1,5 @@ use anyhow::{Result, bail}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; pub enum Attachment { Copy, @@ -62,3 +62,16 @@ impl Attachment { Ok(()) } } + +pub fn filepath(d: &PathBuf, from: &Path, n: usize) -> PathBuf { + let mut to = PathBuf::from(&d); + let f = format!( + "{}{}", + n + 1, + from.extension() + .map(|e| format!(".{}", e.to_string_lossy())) + .unwrap_or_default(), + ); + to.push(&f); + to +}