use super::dom::{attr_value, tags_where};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TabLink {
pub key: String,
pub active: bool,
pub count: Option<u64>,
pub href: String,
}
pub fn tab_links(html: &str) -> Vec<TabLink> {
tags_where(html, |tag, attrs| {
tag == "a" && attr_value(attrs, "data-list-tab").is_some()
})
.into_iter()
.map(|(_, attrs, inner)| TabLink {
key: attr_value(&attrs, "data-list-tab").unwrap_or_default(),
active: attr_value(&attrs, "aria-current").as_deref() == Some("page"),
count: tags_where(&inner, |_, attrs| {
attr_value(attrs, "data-list-tab-count").is_some()
})
.into_iter()
.next()
.and_then(|(_, attrs, _)| attr_value(&attrs, "data-list-tab-count")?.parse().ok()),
href: attr_value(&attrs, "href").unwrap_or_default(),
})
.collect()
}