Merge pull request #63 from Y2Z/poster
Add support for poster attribute
This commit is contained in:
commit
8b3f3f3a6e
5 changed files with 64 additions and 7 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,3 +8,6 @@ Cargo.lock
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Exclude accidental HTML files
|
||||||
|
*.html
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "monolith"
|
name = "monolith"
|
||||||
version = "2.0.18"
|
version = "2.0.19"
|
||||||
authors = [
|
authors = [
|
||||||
"Sunshine <sunshine@uberspace.net>",
|
"Sunshine <sunshine@uberspace.net>",
|
||||||
"Mahdi Robatipoor <mahdi.robatipoor@gmail.com>",
|
"Mahdi Robatipoor <mahdi.robatipoor@gmail.com>",
|
||||||
|
@ -10,9 +10,8 @@ description = "CLI tool for saving web pages as a single HTML file"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.10.1"
|
base64 = "0.10.1"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
html5ever = "0.24.0"
|
html5ever = "0.24.1"
|
||||||
indicatif = "0.11.0"
|
lazy_static = "1.4.0"
|
||||||
lazy_static = "1.3.0"
|
regex = "1.3.1"
|
||||||
regex = "1.2.1"
|
|
||||||
reqwest = "0.9.20"
|
reqwest = "0.9.20"
|
||||||
url = "2.1.0"
|
url = "2.1.0"
|
||||||
|
|
16
Makefile
Normal file
16
Makefile
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
.PHONY: all build install run test lint
|
||||||
|
|
||||||
|
all: test build
|
||||||
|
|
||||||
|
build:
|
||||||
|
@cargo build
|
||||||
|
|
||||||
|
install:
|
||||||
|
@cargo install --force --path .
|
||||||
|
|
||||||
|
test:
|
||||||
|
@cargo test
|
||||||
|
@cargo fmt --all -- --check
|
||||||
|
|
||||||
|
lint:
|
||||||
|
@cargo fmt --all --
|
41
src/html.rs
41
src/html.rs
|
@ -175,7 +175,7 @@ pub fn walk_and_embed_assets(
|
||||||
if &attr.name.local == "src" {
|
if &attr.name.local == "src" {
|
||||||
let value = attr.value.to_string();
|
let value = attr.value.to_string();
|
||||||
|
|
||||||
// Ignore images with empty source (they're hopelessly broken)
|
// Ignore images with empty source
|
||||||
if value == EMPTY_STRING.clone() {
|
if value == EMPTY_STRING.clone() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,14 @@ pub fn walk_and_embed_assets(
|
||||||
}
|
}
|
||||||
"source" => {
|
"source" => {
|
||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "srcset" {
|
let attr_name: &str = &attr.name.local;
|
||||||
|
|
||||||
|
if attr_name == "src" {
|
||||||
|
let src_full_url: String = resolve_url(&url, &attr.value.to_string())
|
||||||
|
.unwrap_or(attr.value.to_string());
|
||||||
|
attr.value.clear();
|
||||||
|
attr.value.push_slice(src_full_url.as_str());
|
||||||
|
} else if attr_name == "srcset" {
|
||||||
if get_node_name(&get_parent_node(&node)) == "picture" {
|
if get_node_name(&get_parent_node(&node)) == "picture" {
|
||||||
if opt_no_images {
|
if opt_no_images {
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
|
@ -345,6 +352,36 @@ pub fn walk_and_embed_assets(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"video" => {
|
||||||
|
for attr in attrs_mut.iter_mut() {
|
||||||
|
if &attr.name.local == "poster" {
|
||||||
|
let video_poster = attr.value.to_string();
|
||||||
|
|
||||||
|
// Ignore posters with empty source
|
||||||
|
if video_poster == EMPTY_STRING.clone() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if opt_no_images {
|
||||||
|
attr.value.clear();
|
||||||
|
} else {
|
||||||
|
let poster_full_url: String = resolve_url(&url, &video_poster)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
|
let img_datauri = retrieve_asset(
|
||||||
|
&poster_full_url,
|
||||||
|
true,
|
||||||
|
"",
|
||||||
|
opt_user_agent,
|
||||||
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(poster_full_url);
|
||||||
|
attr.value.clear();
|
||||||
|
attr.value.push_slice(img_datauri.as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ fn main() {
|
||||||
.index(1)
|
.index(1)
|
||||||
.help("URL to download"),
|
.help("URL to download"),
|
||||||
)
|
)
|
||||||
|
// .args_from_usage("-a, --include-audio 'Embed audio sources'")
|
||||||
.args_from_usage("-c, --no-css 'Ignore styles'")
|
.args_from_usage("-c, --no-css 'Ignore styles'")
|
||||||
.args_from_usage("-f, --no-frames 'Exclude iframes'")
|
.args_from_usage("-f, --no-frames 'Exclude iframes'")
|
||||||
.args_from_usage("-i, --no-images 'Remove images'")
|
.args_from_usage("-i, --no-images 'Remove images'")
|
||||||
|
@ -29,6 +30,7 @@ fn main() {
|
||||||
.args_from_usage("-k, --insecure 'Accept invalid X.509 (TLS) certificates'")
|
.args_from_usage("-k, --insecure 'Accept invalid X.509 (TLS) certificates'")
|
||||||
.args_from_usage("-s, --silent 'Suppress verbosity'")
|
.args_from_usage("-s, --silent 'Suppress verbosity'")
|
||||||
.args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
|
.args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
|
||||||
|
// .args_from_usage("-v, --include-video 'Embed video sources'")
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
// Process the command
|
// Process the command
|
||||||
|
|
Loading…
Add table
Reference in a new issue