Allow HTTP redirects and preserve email links

This commit is contained in:
Vincent Flyson 2019-08-23 16:00:05 -04:00
parent 75969c9943
commit 13429e32d3
4 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "monolith"
version = "2.0.5"
version = "2.0.6"
authors = ["Sunshine <sunshine@uberspace.net>"]
description = "CLI tool to save webpages as a single HTML file"

View File

@ -146,8 +146,8 @@ pub fn walk_and_embed_assets(
NodeMatch::Anchor => {
for attr in attrs_mut.iter_mut() {
if &attr.name.local == "href" {
// Do not touch hrefs which begin with a hash sign
if attr.value.to_string().chars().nth(0) == Some('#') {
// Don't touch email links or hrefs which begin with a hash sign
if attr.value.starts_with('#') || attr.value.starts_with("mailto:") {
continue;
}

View File

@ -1,6 +1,6 @@
use regex::Regex;
use reqwest::header::{CONTENT_TYPE, USER_AGENT};
use reqwest::Client;
use reqwest::{Client, RedirectPolicy};
use std::time::Duration;
use url::{ParseError, Url};
use utils::data_to_dataurl;
@ -75,6 +75,7 @@ pub fn retrieve_asset(
Ok(url.to_string())
} else {
let client = Client::builder()
.redirect(RedirectPolicy::limited(3))
.timeout(Duration::from_secs(10))
.build()
.unwrap();

View File

@ -22,7 +22,7 @@ fn main() {
)
.args_from_usage("-j, --no-js 'Excludes JavaScript'")
.args_from_usage("-i, --no-images 'Removes images'")
.args_from_usage("-u, --user-agent=<Iceweasel> 'Custom User-Agent string'")
.args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
.get_matches();
// Process the command