Struct repo_icons::ReadmeImage
source · pub struct ReadmeImage {
pub src: Url,
pub headers: HashMap<String, String>,
pub in_primary_heading: bool,
pub edge_of_primary_heading: bool,
pub keyword_mentions: HashSet<KeywordMention>,
pub sourced_from_repo: bool,
pub links_to: Option<ProjectLink>,
pub is_align_center: bool,
pub has_size_attrs: bool,
}
Fields§
§src: Url
§headers: HashMap<String, String>
§in_primary_heading: bool
whether the image was in the primary markdown heading
edge_of_primary_heading: bool
whether the image was the first/last one in the heading
keyword_mentions: HashSet<KeywordMention>
whether the image mentions a keyword in its src / alt text
sourced_from_repo: bool
whether the image src points to a file inside of the repo
links_to: Option<ProjectLink>
whether the image has links to the projects
is_align_center: bool
whether the image has the CSS “align: center”
has_size_attrs: bool
whether the image has height or width attributes
Implementations§
source§impl ReadmeImage
impl ReadmeImage
sourcepub async fn get(
readme: &Readme,
elem_ref: &ElementRef<'_>,
primary_heading: &mut PrimaryHeading<'_>
) -> Option<Self>
pub async fn get(
readme: &Readme,
elem_ref: &ElementRef<'_>,
primary_heading: &mut PrimaryHeading<'_>
) -> Option<Self>
Examples found in repository?
src/github_api/readme/mod.rs (line 117)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
pub async fn load_body(&self) -> Result<Vec<ReadmeImage>, Box<dyn Error>> {
let body = gh_api_get!("repos/{}/{}/readme", self.owner, self.repo)
.header("Accept", "application/vnd.github.html")
.send()
.await?
.error_for_status()?
.text()
.await?;
let document = Html::parse_document(&body);
let primary_heading = &mut PrimaryHeading::new(&document);
let mut images = Vec::new();
for element_ref in document.select(selector!("img[src]")) {
if let Some(image) = ReadmeImage::get(self, &element_ref, primary_heading).await {
images.push(image);
}
}
let mut iter = images.iter_mut().enumerate().peekable();
while let Some((idx, image)) = iter.next() {
if image.in_primary_heading
&& (idx == 0
|| iter
.peek()
.map(|(_, image)| !image.in_primary_heading)
.unwrap_or(true))
{
image.edge_of_primary_heading = true;
};
}
images.sort();
warn!(
"{:#?}",
images
.iter()
.map(|img| (img.src.clone(), img.weight()))
.collect::<Vec<_>>()
);
Ok(images)
}
sourcepub fn weight(&self) -> u8
pub fn weight(&self) -> u8
Examples found in repository?
More examples
src/github_api/readme/mod.rs (line 141)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
pub async fn load_body(&self) -> Result<Vec<ReadmeImage>, Box<dyn Error>> {
let body = gh_api_get!("repos/{}/{}/readme", self.owner, self.repo)
.header("Accept", "application/vnd.github.html")
.send()
.await?
.error_for_status()?
.text()
.await?;
let document = Html::parse_document(&body);
let primary_heading = &mut PrimaryHeading::new(&document);
let mut images = Vec::new();
for element_ref in document.select(selector!("img[src]")) {
if let Some(image) = ReadmeImage::get(self, &element_ref, primary_heading).await {
images.push(image);
}
}
let mut iter = images.iter_mut().enumerate().peekable();
while let Some((idx, image)) = iter.next() {
if image.in_primary_heading
&& (idx == 0
|| iter
.peek()
.map(|(_, image)| !image.in_primary_heading)
.unwrap_or(true))
{
image.edge_of_primary_heading = true;
};
}
images.sort();
warn!(
"{:#?}",
images
.iter()
.map(|img| (img.src.clone(), img.weight()))
.collect::<Vec<_>>()
);
Ok(images)
}
Trait Implementations§
source§impl Debug for ReadmeImage
impl Debug for ReadmeImage
source§impl<'de> Deserialize<'de> for ReadmeImage
impl<'de> Deserialize<'de> for ReadmeImage
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for ReadmeImage
impl Ord for ReadmeImage
source§impl PartialEq<ReadmeImage> for ReadmeImage
impl PartialEq<ReadmeImage> for ReadmeImage
source§fn eq(&self, other: &ReadmeImage) -> bool
fn eq(&self, other: &ReadmeImage) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<ReadmeImage> for ReadmeImage
impl PartialOrd<ReadmeImage> for ReadmeImage
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for ReadmeImage
impl Serialize for ReadmeImage
impl Eq for ReadmeImage
impl StructuralEq for ReadmeImage
impl StructuralPartialEq for ReadmeImage
Auto Trait Implementations§
impl RefUnwindSafe for ReadmeImage
impl Send for ReadmeImage
impl Sync for ReadmeImage
impl Unpin for ReadmeImage
impl UnwindSafe for ReadmeImage
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.