image generation is now always wanted
Some checks failed
test / cargo test (push) Failing after 1m4s
Some checks failed
test / cargo test (push) Failing after 1m4s
This commit is contained in:
parent
11cc9f6d0a
commit
d9d17bb971
@ -69,8 +69,9 @@ pub fn parse_markdown(markdown: &str) -> ::askama::Result<String> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Place image into the content with scaled reso to a boundary
|
// Place image into the content with scaled reso to a boundary
|
||||||
let picture_markup =
|
let picture_markup = generate_picture_markup(
|
||||||
generate_picture_markup(&dest_url, max_width, max_height, &title, None, true)
|
&dest_url, max_width, max_height, &title, None,
|
||||||
|
)
|
||||||
.unwrap_or(formatdoc!(
|
.unwrap_or(formatdoc!(
|
||||||
r#"
|
r#"
|
||||||
<img
|
<img
|
||||||
@ -165,8 +166,5 @@ pub fn parse_markdown(markdown: &str) -> ::askama::Result<String> {
|
|||||||
// Write to String buffer
|
// Write to String buffer
|
||||||
let mut html = String::new();
|
let mut html = String::new();
|
||||||
pulldown_cmark::html::push_html(&mut html, parser);
|
pulldown_cmark::html::push_html(&mut html, parser);
|
||||||
// filters::safe(Html, html)
|
|
||||||
// filters::escape(Text, html)
|
|
||||||
// Ok(html)
|
|
||||||
Ok(html)
|
Ok(html)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ pub fn generate_image_with_src(
|
|||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
suffix: &str,
|
suffix: &str,
|
||||||
generate_image: bool,
|
|
||||||
) -> Result<String, anyhow::Error> {
|
) -> Result<String, anyhow::Error> {
|
||||||
let path_to_generated = get_generated_file_name(orig_img_path);
|
let path_to_generated = get_generated_file_name(orig_img_path);
|
||||||
let file_stem = path_to_generated.file_stem().unwrap().to_str().unwrap();
|
let file_stem = path_to_generated.file_stem().unwrap().to_str().unwrap();
|
||||||
@ -29,7 +28,6 @@ pub fn generate_image_with_src(
|
|||||||
let path_to_generated_arc = Arc::new(path_to_generated);
|
let path_to_generated_arc = Arc::new(path_to_generated);
|
||||||
let path_to_generated_clone = Arc::clone(&path_to_generated_arc);
|
let path_to_generated_clone = Arc::clone(&path_to_generated_arc);
|
||||||
|
|
||||||
if generate_image {
|
|
||||||
rayon::spawn(move || {
|
rayon::spawn(move || {
|
||||||
let orig_img = ImageReader::open(&disk_img_path)
|
let orig_img = ImageReader::open(&disk_img_path)
|
||||||
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
|
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
|
||||||
@ -49,7 +47,7 @@ pub fn generate_image_with_src(
|
|||||||
tracing::error!("Error: {}", e);
|
tracing::error!("Error: {}", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
let path_to_generated = Arc::clone(&path_to_generated_arc);
|
let path_to_generated = Arc::clone(&path_to_generated_arc);
|
||||||
|
|
||||||
let image_path = get_image_path(
|
let image_path = get_image_path(
|
||||||
|
@ -20,7 +20,6 @@ pub fn generate_picture_markup(
|
|||||||
height: u32,
|
height: u32,
|
||||||
alt_text: &str,
|
alt_text: &str,
|
||||||
class_name: Option<&str>,
|
class_name: Option<&str>,
|
||||||
generate_image: bool,
|
|
||||||
) -> Result<String, anyhow::Error> {
|
) -> Result<String, anyhow::Error> {
|
||||||
let exported_formats = get_export_formats(orig_img_path);
|
let exported_formats = get_export_formats(orig_img_path);
|
||||||
let class_attr = if let Some(class) = class_name {
|
let class_attr = if let Some(class) = class_name {
|
||||||
@ -55,7 +54,6 @@ pub fn generate_picture_markup(
|
|||||||
let exported_formats_arc = Arc::new(exported_formats);
|
let exported_formats_arc = Arc::new(exported_formats);
|
||||||
let exported_formats_clone = Arc::clone(&exported_formats_arc);
|
let exported_formats_clone = Arc::clone(&exported_formats_arc);
|
||||||
|
|
||||||
if generate_image {
|
|
||||||
rayon::spawn(move || {
|
rayon::spawn(move || {
|
||||||
let orig_img = ImageReader::open(&disk_img_path)
|
let orig_img = ImageReader::open(&disk_img_path)
|
||||||
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
|
.with_context(|| format!("Failed to read instrs from {:?}", &disk_img_path))
|
||||||
@ -66,14 +64,12 @@ pub fn generate_picture_markup(
|
|||||||
let resolutions = resolutions_clone.as_ref();
|
let resolutions = resolutions_clone.as_ref();
|
||||||
let exported_formats = exported_formats_clone.as_ref();
|
let exported_formats = exported_formats_clone.as_ref();
|
||||||
|
|
||||||
let result =
|
let result = generate_images(&orig_img, path_to_generated, resolutions, exported_formats)
|
||||||
generate_images(&orig_img, path_to_generated, resolutions, exported_formats)
|
|
||||||
.with_context(|| "Failed to generate images".to_string());
|
.with_context(|| "Failed to generate images".to_string());
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
tracing::error!("Error: {}", e);
|
tracing::error!("Error: {}", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
let exported_formats = Arc::clone(&exported_formats_arc);
|
let exported_formats = Arc::clone(&exported_formats_arc);
|
||||||
let path_to_generated = Arc::clone(&path_to_generated_arc);
|
let path_to_generated = Arc::clone(&path_to_generated_arc);
|
||||||
@ -314,14 +310,7 @@ fn test_generate_picture_markup() {
|
|||||||
</picture>"#,
|
</picture>"#,
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
generate_picture_markup(
|
generate_picture_markup(orig_img_path, width, height, "Testing image alt", None,)
|
||||||
orig_img_path,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
"Testing image alt",
|
|
||||||
None,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
.expect("picture markup has to be generated"),
|
.expect("picture markup has to be generated"),
|
||||||
result
|
result
|
||||||
);
|
);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<meta property="og:url" content="https://michalvanko.dev/{{segment}}/{{slug}}" />
|
<meta property="og:url" content="https://michalvanko.dev/{{segment}}/{{slug}}" />
|
||||||
{% match thumbnail %}
|
{% match thumbnail %}
|
||||||
{% when Some with (img) %}
|
{% when Some with (img) %}
|
||||||
{% let src = crate::picture_generator::image_src_generator::generate_image_with_src(img, 1200, 630, "_og", true).unwrap_or("thumbnail not found".to_string())|safe %}
|
{% let src = crate::picture_generator::image_src_generator::generate_image_with_src(img, 1200, 630, "_og").unwrap_or("thumbnail not found".to_string())|safe %}
|
||||||
<meta property="og:image" content="https://michalvanko.dev{{src}}" />
|
<meta property="og:image" content="https://michalvanko.dev{{src}}" />
|
||||||
{% when None %}
|
{% when None %}
|
||||||
<meta property="og:image" content="https://michalvanko.dev/images/m-logo.svg" />
|
<meta property="og:image" content="https://michalvanko.dev/images/m-logo.svg" />
|
||||||
@ -28,7 +28,7 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section class="article-body">
|
<section class="article-body">
|
||||||
{{body|parse_markdown|escape("none")}}
|
{{body|parse_markdown|safe}}
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<aside class="row-span-3 self-center float-start sm:float-none mr-3 mb-3 sm:ml-0 sm:mb-0">
|
<aside class="row-span-3 self-center float-start sm:float-none mr-3 mb-3 sm:ml-0 sm:mb-0">
|
||||||
{% match post.metadata.thumbnail %}
|
{% match post.metadata.thumbnail %}
|
||||||
{% when Some with (orig_path) %}
|
{% when Some with (orig_path) %}
|
||||||
{{ crate::picture_generator::picture_markup_generator::generate_picture_markup(orig_path, 180, 240, "Article thumbnail", None, true).unwrap_or("thumbnail not found".to_string())|safe }}
|
{{ crate::picture_generator::picture_markup_generator::generate_picture_markup(orig_path, 180, 240, "Article thumbnail", None).unwrap_or("thumbnail not found".to_string())|safe }}
|
||||||
{% when None %}
|
{% when None %}
|
||||||
<div>
|
<div>
|
||||||
{% include "components/blog_post_default_thumbnail.html" %}
|
{% include "components/blog_post_default_thumbnail.html" %}
|
||||||
@ -14,7 +14,7 @@
|
|||||||
<a rel="prefetch" href="/{{segment}}/{{post.slug}}" class="text-blue-950 visited:text-purple-700 no-underline">{{post.metadata.title}}</a>
|
<a rel="prefetch" href="/{{segment}}/{{post.slug}}" class="text-blue-950 visited:text-purple-700 no-underline">{{post.metadata.title}}</a>
|
||||||
</h3>
|
</h3>
|
||||||
</header>
|
</header>
|
||||||
<section class="text-base leading-5 text-slate-800 md:text-xl text-justify">{{post.body|truncate_md(2)|parse_markdown|escape("none")}}</section>
|
<section class="text-base leading-5 text-slate-800 md:text-xl text-justify">{{post.body|truncate_md(2)|parse_markdown|safe}}</section>
|
||||||
<footer class="text-sm md:text-base lg:text-lg mt-3 sm:mt-0 clear-both sm:clear-none">
|
<footer class="text-sm md:text-base lg:text-lg mt-3 sm:mt-0 clear-both sm:clear-none">
|
||||||
<ul class="inline-block">
|
<ul class="inline-block">
|
||||||
{% for tag in post.metadata.tags %}
|
{% for tag in post.metadata.tags %}
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
</h2>
|
</h2>
|
||||||
<section class="description text-slate-800 my-2 md:text-xl text-justify">
|
<section class="description text-slate-800 my-2 md:text-xl text-justify">
|
||||||
{{project.body|parse_markdown|escape("none")}}
|
{{project.body|parse_markdown|safe}}
|
||||||
</section>
|
</section>
|
||||||
</header>
|
</header>
|
||||||
<!-- <hr class="border-blue-950 my-5"> -->
|
<!-- <hr class="border-blue-950 my-5"> -->
|
||||||
|
|
||||||
{% match project.metadata.cover_image %}
|
{% match project.metadata.cover_image %}
|
||||||
{% when Some with (source) %}
|
{% when Some with (source) %}
|
||||||
{% let picture = crate::picture_generator::picture_markup_generator::generate_picture_markup(source, 420, 236, "Project cover", Some("max-h-[236px]"), true).unwrap_or("cover not found".to_string()) %}
|
{% let picture = crate::picture_generator::picture_markup_generator::generate_picture_markup(source, 420, 236, "Project cover", Some("max-h-[236px]")).unwrap_or("cover not found".to_string()) %}
|
||||||
<figure class="mx-4 my-2 flex justify-center">
|
<figure class="mx-4 my-2 flex justify-center">
|
||||||
{% match project.metadata.link %}
|
{% match project.metadata.link %}
|
||||||
{% when Some with (href) %}
|
{% when Some with (href) %}
|
||||||
@ -28,7 +28,6 @@
|
|||||||
{% when None %}
|
{% when None %}
|
||||||
{{picture|safe}}
|
{{picture|safe}}
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
<!-- TODO <figure> generate_image -->
|
|
||||||
</figure>
|
</figure>
|
||||||
{% when None %}
|
{% when None %}
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
</header>
|
</header>
|
||||||
{% let alt_text = format!("{svg} thumbnail") %}
|
{% let alt_text = format!("{svg} thumbnail") %}
|
||||||
|
|
||||||
{{ crate::picture_generator::picture_markup_generator::generate_picture_markup(img, 360, 128, alt_text, Some("h-auto mx-auto rounded-sm"), true).unwrap_or("thumbnail not found".to_string())|safe }}
|
{{ crate::picture_generator::picture_markup_generator::generate_picture_markup(img, 360, 128, alt_text, Some("h-auto mx-auto rounded-sm")).unwrap_or("thumbnail not found".to_string())|safe }}
|
||||||
</a>
|
</a>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
Loading…
Reference in New Issue
Block a user