From 9932b81627ef3fc57511b4775bd1b2074598b754 Mon Sep 17 00:00:00 2001 From: Bartal Laearsson Date: Tue, 18 Aug 2026 11:18:03 +0100 Subject: [PATCH] add single page html to md --- src/main.rs | 11 +++++++++++ src/scraper.rs | 30 +++++++++++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 864c76e..4416f44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,12 @@ struct Args { #[arg(help = "Starting URL to scrape")] start_url: String, + #[arg( + long, + help = "Only scrape the single page at START_URL, do not crawl for links" + )] + single: bool, + #[arg(long, help = "Save documents as-is, skip Markdown conversion")] no_doc_conversion: bool, @@ -128,6 +134,10 @@ async fn main() -> Result<()> { "Document conversion: {}", if convert_docs { "enabled" } else { "disabled" } ); + log::info!( + "Single page mode: {}", + if args.single { "enabled" } else { "disabled" } + ); match (&include_types, &exclude_types) { (Some(t), _) => log::info!("Type filter: include {:?}", t), @@ -160,6 +170,7 @@ async fn main() -> Result<()> { include_types, exclude_types, scope_path, + args.single, ); let (count, errors) = scraper.run(&url).await; diff --git a/src/scraper.rs b/src/scraper.rs index 77c83d4..e48d796 100644 --- a/src/scraper.rs +++ b/src/scraper.rs @@ -41,6 +41,7 @@ pub struct Scraper { include_types: Option>, exclude_types: Option>, scope_path: Option, + single_page: bool, } impl Scraper { @@ -54,6 +55,7 @@ impl Scraper { include_types: Option>, exclude_types: Option>, scope_path: Option, + single_page: bool, ) -> Self { Self { fetcher, @@ -67,6 +69,7 @@ impl Scraper { include_types, exclude_types, scope_path, + single_page, } } @@ -164,20 +167,24 @@ impl Scraper { } if is_html { - if let Ok(html) = std::str::from_utf8(&result.bytes) { - let links = extract_links(html, &final_url, &self.base_domain); - let new_count = links.len(); + if !self.single_page { + if let Ok(html) = std::str::from_utf8(&result.bytes) { + let links = extract_links(html, &final_url, &self.base_domain); + let new_count = links.len(); - let new_links: Vec = links - .into_iter() - .filter(|link| !self.seen.contains(link.as_str())) - .collect(); + let new_links: Vec = links + .into_iter() + .filter(|link| !self.seen.contains(link.as_str())) + .collect(); - for link in &new_links { - queue.push_back(link.clone()); + for link in &new_links { + queue.push_back(link.clone()); + } + + log::info!(" found {} links ({} new)", new_count, new_links.len()); } - - log::info!(" found {} links ({} new)", new_count, new_links.len()); + } else { + log::info!(" [single-page mode] not crawling for links"); } } } @@ -303,6 +310,7 @@ mod tests { include_types, exclude_types, scope_path: None, + single_page: false, } }