holy shit the responsiveness
Some checks failed
test / cargo test (push) Failing after 1m24s

This commit is contained in:
2024-09-25 12:55:05 +02:00
parent fc26d77bfc
commit 1eb0f55264
9 changed files with 140 additions and 102 deletions

View File

@ -19,9 +19,15 @@ pub fn generate_picture_markup(
width: u32,
height: u32,
alt_text: &str,
class_name: Option<&str>,
generate_image: bool,
) -> Result<String, anyhow::Error> {
let exported_formats = get_export_formats(orig_img_path);
let class_attr = if let Some(class) = class_name {
format!(r#"class="{class}""#)
} else {
"".to_string()
};
if exported_formats.is_empty() {
return Ok(formatdoc!(
@ -29,6 +35,7 @@ pub fn generate_picture_markup(
src="{orig_img_path}"
width="{width}"
height="{height}"
{class_attr}
alt="{alt_text}"
>"#
));
@ -99,6 +106,7 @@ pub fn generate_picture_markup(
width="{width}"
height="{height}"
alt="{alt_text}"
{class_attr}
>"#
);
@ -307,8 +315,15 @@ fn test_generate_picture_markup() {
</picture>"#,
};
assert_eq!(
generate_picture_markup(orig_img_path, width, height, "Testing image alt", false)
.expect("picture markup has to be generated"),
generate_picture_markup(
orig_img_path,
width,
height,
"Testing image alt",
None,
false
)
.expect("picture markup has to be generated"),
result
);
}

View File

@ -125,17 +125,23 @@ pub fn parse_html(markdown: &str, generate_images: bool) -> String {
);
// Place image into the content with scaled reso to a boundary
let picture_markup =
generate_picture_markup(&dest_url, max_width, max_height, &title, generate_images)
.unwrap_or(formatdoc!(
r#"
let picture_markup = generate_picture_markup(
&dest_url,
max_width,
max_height,
&title,
None,
generate_images,
)
.unwrap_or(formatdoc!(
r#"
<img
alt="{alt}"
src="{src}"
/>"#,
alt = title,
src = dest_url,
));
alt = title,
src = dest_url,
));
debug!(
"Image link_type: {:?} url: {} title: {} id: {}",
link_type, dest_url, title, id