Small code improvements
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
This commit is contained in:
parent
8f6f9c6e79
commit
f7815e3406
|
@ -16,7 +16,7 @@ Converts a newsletter to static HTML files.
|
|||
* [X] Generate static HTML files
|
||||
* [ ] Parse and add unsubscribe link
|
||||
* [ ] Where possible: remove tracking pixels / images
|
||||
* [ ] Prevent loading of scripts / images without user interaction
|
||||
* [X] Prevent loading of scripts / images without user interaction
|
||||
|
||||
### Create ATOM feed
|
||||
|
||||
|
|
|
@ -37,37 +37,24 @@ fn main() {
|
|||
|
||||
println!("{}", &title);
|
||||
|
||||
let html_body = parsed.get_html_body(0).expect("Could not read body");
|
||||
|
||||
let html_body = parsed.get_html_body(0).expect("Could not read html body");
|
||||
let processed_html = process_html(&html_body).expect("Could not process the HTML");
|
||||
let html_bytes = processed_html.as_bytes();
|
||||
|
||||
//println!("{}", &html_body);
|
||||
|
||||
let hash = base16ct::lower::encode_string(&Sha256::digest(&html_bytes));
|
||||
println!("{}", hash);
|
||||
|
||||
// let dom = kuchiki::parse_html().one(String::from_utf8(html_bytes.to_vec()).expect("Could not convert HTML bytes to string"));
|
||||
// for img_match in dom.select("img").unwrap() {
|
||||
// let mut attributes = img_match.attributes.borrow_mut();
|
||||
// let src = { attributes.get("src").unwrap_or_default() }.to_owned();
|
||||
// attributes.remove("src");
|
||||
// attributes.insert("data-src", src.to_owned());
|
||||
// }
|
||||
|
||||
// let new_html = dom.as_text()
|
||||
|
||||
let path: PathBuf = [dir, Path::new(&format!("{}.html", &title))]
|
||||
let html_path: PathBuf = [dir, Path::new(&format!("{}.html", &title))]
|
||||
.iter()
|
||||
.collect();
|
||||
let mut file = OpenOptions::new()
|
||||
|
||||
OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(path)
|
||||
.expect("Could not open file fir writing");
|
||||
|
||||
file.write_all(&html_bytes)
|
||||
.expect("Could not write to file.");
|
||||
.open(&html_path)
|
||||
.expect(format!("Could not open file '{}' for writing", &html_path.display()).as_str())
|
||||
.write_all(&html_bytes)
|
||||
.expect(format!("Could not write html to file '{}'.", &html_path.display()).as_str());
|
||||
|
||||
println!();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue