|
|
|
@ -113,14 +113,9 @@ fn build_feed(filename: &PathBuf, hostname: String, include_html: bool) -> Resul
|
|
|
|
|
feed.set_updated(Utc::now());
|
|
|
|
|
println!("Writing feed to {}", filename.display());
|
|
|
|
|
|
|
|
|
|
// TODO: Ugly hack because atom_syndication crate does not support style sheets.
|
|
|
|
|
let feed_str = feed.to_string().as_str().replace(">\n<feed", ">\n<?xml-stylesheet href=\"feed.xsl\" type=\"text/xsl\"?>\n<feed");
|
|
|
|
|
let _ = write_file(filename, feed_str)?;
|
|
|
|
|
let _ = write_file(dir.join("feed.xsl"), FEED_STYLESHEET)?;
|
|
|
|
|
|
|
|
|
|
// Another ugly hack, but I don't know how to do this better...
|
|
|
|
|
let file_name = format!("{:?}", filename.file_name().unwrap()).replace('"', "");
|
|
|
|
|
write_file(dir.join("index.html"), INDEX_HTML.replace("{FEED}", file_name.as_str()))?;
|
|
|
|
|
feed::write_feed(feed, open_file(filename).unwrap())?;
|
|
|
|
|
write_file(dir.join("feed.xsl"), FEED_STYLESHEET)?;
|
|
|
|
|
write_file(dir.join("index.html"), INDEX_HTML.replace("{FEED}", feed_file))?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println!("Finished building the feed.");
|
|
|
|
@ -209,12 +204,16 @@ fn process_html(input: &str) -> Result<String, ()> {
|
|
|
|
|
Ok(input.replace("src", "data-source"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn write_file<P: Into<PathBuf>, D: AsRef<[u8]>>(html_path: P, data: D) -> Result<(), std::io::Error> {
|
|
|
|
|
let path : PathBuf = html_path.into();
|
|
|
|
|
fn open_file<P: Into<PathBuf>>(path: P) -> std::io::Result<std::fs::File> {
|
|
|
|
|
OpenOptions::new()
|
|
|
|
|
.write(true)
|
|
|
|
|
.create(true)
|
|
|
|
|
.open(&path)
|
|
|
|
|
.expect(format!("Could not open file '{}' for writing", &path.display()).as_str())
|
|
|
|
|
.open(path.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn write_file<P: Into<PathBuf>, D: AsRef<[u8]>>(path: P, data: D) -> Result<(), std::io::Error> {
|
|
|
|
|
let path: PathBuf = path.into();
|
|
|
|
|
open_file(path.clone())
|
|
|
|
|
.unwrap_or_else(|_| panic!("Could not open file '{}' for writing", &path.display()))
|
|
|
|
|
.write_all(data.as_ref())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|