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§

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)
  }
Examples found in repository?
src/github_api/readme/readme_image.rs (line 212)
211
212
213
  fn cmp(&self, other: &Self) -> Ordering {
    other.weight().cmp(&self.weight())
  }
More examples
Hide additional 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§

Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more