0.4.3: fix bug & increase SiteLogo weight for first match
This commit is contained in:
parent
d95824a11d
commit
76e84100a4
3 changed files with 15 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1638,7 +1638,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "site_icons"
|
name = "site_icons"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "site_icons"
|
name = "site_icons"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
20
src/icons.rs
20
src/icons.rs
|
@ -187,15 +187,17 @@ impl Icons {
|
||||||
"img[alt*=logo], svg[alt*=logo]",
|
"img[alt*=logo], svg[alt*=logo]",
|
||||||
"img[class*=logo], svg[class*=logo]",
|
"img[class*=logo], svg[class*=logo]",
|
||||||
))
|
))
|
||||||
.filter_map(|elem_ref| {
|
.enumerate()
|
||||||
let mut ancestors = elem_ref
|
.filter_map(|(i, elem_ref)| {
|
||||||
|
let ancestors = elem_ref
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.map(ElementRef::wrap)
|
.map(ElementRef::wrap)
|
||||||
.flatten()
|
.flatten()
|
||||||
.map(|elem_ref| elem_ref.value());
|
.map(|elem_ref| elem_ref.value())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let skip_classnames = regex!("menu|search");
|
let skip_classnames = regex!("menu|search");
|
||||||
let should_skip = ancestors.any(|ancestor| {
|
let should_skip = ancestors.iter().any(|ancestor| {
|
||||||
ancestor
|
ancestor
|
||||||
.attr("class")
|
.attr("class")
|
||||||
.map(|attr| skip_classnames.is_match(&attr.to_lowercase()))
|
.map(|attr| skip_classnames.is_match(&attr.to_lowercase()))
|
||||||
|
@ -214,12 +216,16 @@ impl Icons {
|
||||||
let mut weight = 0;
|
let mut weight = 0;
|
||||||
|
|
||||||
// if in the header
|
// if in the header
|
||||||
if ancestors.any(|element| element.name() == "header") {
|
if ancestors.iter().any(|element| element.name() == "header") {
|
||||||
weight += 2;
|
weight += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut mentions_logo = |attr_name| {
|
if i == 0 {
|
||||||
ancestors.any(|ancestor| {
|
weight += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentions_logo = |attr_name| {
|
||||||
|
ancestors.iter().any(|ancestor| {
|
||||||
ancestor
|
ancestor
|
||||||
.attr(attr_name)
|
.attr(attr_name)
|
||||||
.map(|attr| regex!("logo([^s]|$)").is_match(&attr.to_lowercase()))
|
.map(|attr| regex!("logo([^s]|$)").is_match(&attr.to_lowercase()))
|
||||||
|
|
Reference in a new issue