define link type of <link> element as enum and prefer match statement
since match statement checks exhaustiveness
This commit is contained in:
parent
929512f4f5
commit
660511b8a0
34
src/html.rs
34
src/html.rs
@ -82,8 +82,6 @@ pub fn walk_and_embed_assets(
|
|||||||
|
|
||||||
match name.local.as_ref() {
|
match name.local.as_ref() {
|
||||||
"link" => {
|
"link" => {
|
||||||
let mut link_type: &str = "";
|
|
||||||
|
|
||||||
// Remove integrity attributes
|
// Remove integrity attributes
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < attrs_mut.len() {
|
while i < attrs_mut.len() {
|
||||||
@ -95,26 +93,37 @@ pub fn walk_and_embed_assets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LinkType {
|
||||||
|
Icon,
|
||||||
|
Stylesheet,
|
||||||
|
Preload,
|
||||||
|
DnsPrefetch,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut link_type = LinkType::Unknown;
|
||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "rel" {
|
if &attr.name.local == "rel" {
|
||||||
if is_icon(attr.value.as_ref()) {
|
if is_icon(attr.value.as_ref()) {
|
||||||
link_type = "icon";
|
link_type = LinkType::Icon;
|
||||||
break;
|
break;
|
||||||
} else if attr.value.as_ref() == "stylesheet" {
|
} else if attr.value.as_ref() == "stylesheet" {
|
||||||
link_type = "stylesheet";
|
link_type = LinkType::Stylesheet;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let link_type = link_type;
|
||||||
|
|
||||||
if link_type == "icon" {
|
match link_type {
|
||||||
|
LinkType::Icon => {
|
||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "href" {
|
if &attr.name.local == "href" {
|
||||||
if opt_no_images {
|
if opt_no_images {
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
} else {
|
} else {
|
||||||
let href_full_url =
|
let href_full_url = resolve_url(&url, attr.value.as_ref())
|
||||||
resolve_url(&url, attr.value.as_ref()).unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let (favicon_dataurl, _) = retrieve_asset(
|
let (favicon_dataurl, _) = retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -129,14 +138,15 @@ pub fn walk_and_embed_assets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if link_type == "stylesheet" {
|
}
|
||||||
|
LinkType::Stylesheet => {
|
||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "href" {
|
if &attr.name.local == "href" {
|
||||||
if opt_no_css {
|
if opt_no_css {
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
} else {
|
} else {
|
||||||
let href_full_url =
|
let href_full_url = resolve_url(&url, &attr.value.as_ref())
|
||||||
resolve_url(&url, &attr.value.as_ref()).unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let replacement_text = match retrieve_asset(
|
let replacement_text = match retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -170,7 +180,8 @@ pub fn walk_and_embed_assets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
LinkType::Unknown => {
|
||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "href" {
|
if &attr.name.local == "href" {
|
||||||
let href_full_url =
|
let href_full_url =
|
||||||
@ -181,6 +192,7 @@ pub fn walk_and_embed_assets(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
"img" => {
|
"img" => {
|
||||||
// Find source tags
|
// Find source tags
|
||||||
let mut found_src: Option<Attribute> = None;
|
let mut found_src: Option<Attribute> = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user