Merge pull request #23 from Y2Z/bug-fixes

Allow HTTP redirects and preserve email links
pull/24/head
Vincent Flyson 5 years ago committed by GitHub
commit a23cc0b5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

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

@ -22,7 +22,7 @@ fn main() {
) )
.args_from_usage("-j, --no-js 'Excludes JavaScript'") .args_from_usage("-j, --no-js 'Excludes JavaScript'")
.args_from_usage("-i, --no-images 'Removes images'") .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(); .get_matches();
// Process the command // Process the command

Loading…
Cancel
Save