Add simplification logging
Signed-off-by: Evan Lloyd New-Schmidt <evan@new-schmidt.com>
This commit is contained in:
parent
c9eb7a160a
commit
32cd084f3f
2 changed files with 14 additions and 0 deletions
|
@ -52,10 +52,12 @@ pub fn simplify(html: &str, lang: &str) -> String {
|
|||
if bad_sections.contains(&title.trim()) {
|
||||
to_remove.push(header.id());
|
||||
let header_level = header.value().name();
|
||||
trace!("Removing section for header {header_level} {title:?}");
|
||||
// Strip trailing nodes.
|
||||
for sibling in header.next_siblings() {
|
||||
if let Some(element) = sibling.value().as_element() {
|
||||
if element.name() == header_level {
|
||||
trace!("Stopping removal at {}", element.name(),);
|
||||
// TODO: Should this check for a higher level?
|
||||
break;
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -3,6 +3,7 @@ use std::{
|
|||
io::{stdin, stdout, BufReader, Read, Write},
|
||||
num::NonZeroUsize,
|
||||
path::PathBuf,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use clap::{CommandFactory, Parser, Subcommand};
|
||||
|
@ -89,7 +90,18 @@ fn main() -> anyhow::Result<()> {
|
|||
let mut input = String::new();
|
||||
stdin().read_to_string(&mut input)?;
|
||||
|
||||
let start = Instant::now();
|
||||
let output = om_wikiparser::html::simplify(&input, &lang);
|
||||
let stop = Instant::now();
|
||||
let time = stop.duration_since(start);
|
||||
|
||||
{
|
||||
let input_size = input.len() as isize;
|
||||
let output_size = output.len() as isize;
|
||||
let difference = input_size - output_size;
|
||||
let scale = input_size as f64 / output_size as f64;
|
||||
info!("Reduced size by {difference} bytes ({scale:.4}x) in {time:?}");
|
||||
}
|
||||
|
||||
stdout().write_all(output.as_bytes())?;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue