image generation is now always wanted
Some checks failed
test / cargo test (push) Failing after 1m4s

This commit is contained in:
2024-10-07 15:42:54 +02:00
parent 11cc9f6d0a
commit d9d17bb971
7 changed files with 51 additions and 67 deletions

View File

@ -69,17 +69,18 @@ pub fn parse_markdown(markdown: &str) -> ::askama::Result<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, None, true)
.unwrap_or(formatdoc!(
r#"
let picture_markup = generate_picture_markup(
&dest_url, max_width, max_height, &title, None,
)
.unwrap_or(formatdoc!(
r#"
<img
alt="{alt}"
src="{src}"
/>"#,
alt = title,
src = dest_url,
));
alt = title,
src = dest_url,
));
Event::Html(
formatdoc!(
r#"<figure>
@ -165,8 +166,5 @@ pub fn parse_markdown(markdown: &str) -> ::askama::Result<String> {
// Write to String buffer
let mut html = String::new();
pulldown_cmark::html::push_html(&mut html, parser);
// filters::safe(Html, html)
// filters::escape(Text, html)
// Ok(html)
Ok(html)
}

View File

@ -13,7 +13,6 @@ pub fn generate_image_with_src(
width: u32,
height: u32,
suffix: &str,
generate_image: bool,
) -> Result<String, anyhow::Error> {
let path_to_generated = get_generated_file_name(orig_img_path);
let file_stem = path_to_generated.file_stem().unwrap().to_str().unwrap();
@ -29,27 +28,26 @@ pub fn generate_image_with_src(
let path_to_generated_arc = Arc::new(path_to_generated);
let path_to_generated_clone = Arc::clone(&path_to_generated_arc);
if generate_image {
rayon::spawn(move || {
let orig_img = ImageReader::open(&disk_img_path)
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
.unwrap()
.decode()
.unwrap();
let path_to_generated = path_to_generated_clone.as_ref();
rayon::spawn(move || {
let orig_img = ImageReader::open(&disk_img_path)
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
.unwrap()
.decode()
.unwrap();
let path_to_generated = path_to_generated_clone.as_ref();
let result = generate_images(
&orig_img,
path_to_generated,
&resolutions,
&[exported_format],
)
.with_context(|| "Failed to generate images".to_string());
if let Err(e) = result {
tracing::error!("Error: {}", e);
}
});
let result = generate_images(
&orig_img,
path_to_generated,
&resolutions,
&[exported_format],
)
.with_context(|| "Failed to generate images".to_string());
if let Err(e) = result {
tracing::error!("Error: {}", e);
}
});
}
let path_to_generated = Arc::clone(&path_to_generated_arc);
let image_path = get_image_path(

View File

@ -20,7 +20,6 @@ pub fn generate_picture_markup(
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 {
@ -55,25 +54,22 @@ pub fn generate_picture_markup(
let exported_formats_arc = Arc::new(exported_formats);
let exported_formats_clone = Arc::clone(&exported_formats_arc);
if generate_image {
rayon::spawn(move || {
let orig_img = ImageReader::open(&disk_img_path)
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
.unwrap()
.decode()
.unwrap();
let path_to_generated = path_to_generated_clone.as_ref();
let resolutions = resolutions_clone.as_ref();
let exported_formats = exported_formats_clone.as_ref();
rayon::spawn(move || {
let orig_img = ImageReader::open(&disk_img_path)
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
.unwrap()
.decode()
.unwrap();
let path_to_generated = path_to_generated_clone.as_ref();
let resolutions = resolutions_clone.as_ref();
let exported_formats = exported_formats_clone.as_ref();
let result =
generate_images(&orig_img, path_to_generated, resolutions, exported_formats)
.with_context(|| "Failed to generate images".to_string());
if let Err(e) = result {
tracing::error!("Error: {}", e);
}
});
}
let result = generate_images(&orig_img, path_to_generated, resolutions, exported_formats)
.with_context(|| "Failed to generate images".to_string());
if let Err(e) = result {
tracing::error!("Error: {}", e);
}
});
let exported_formats = Arc::clone(&exported_formats_arc);
let path_to_generated = Arc::clone(&path_to_generated_arc);
@ -314,15 +310,8 @@ fn test_generate_picture_markup() {
</picture>"#,
};
assert_eq!(
generate_picture_markup(
orig_img_path,
width,
height,
"Testing image alt",
None,
false
)
.expect("picture markup has to be generated"),
generate_picture_markup(orig_img_path, width, height, "Testing image alt", None,)
.expect("picture markup has to be generated"),
result
);
}