Merge pull request #23 from Y2Z/bug-fixes

Allow HTTP redirects and preserve email links
This commit is contained in:
Vincent Flyson 2019-08-23 16:01:22 -04:00 committed by GitHub
commit a23cc0b5b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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