From 25cd6c9294b906f8d4f8e3f0d3e1544d6081b87b Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Wed, 13 May 2026 23:32:08 +0200 Subject: [PATCH] fix: handle absolute poster URLs from federated instances in templates --- crates/adapters/template-askama/src/lib.rs | 12 ++++++++++++ .../template-askama/templates/activity_feed.html | 2 +- crates/adapters/template-askama/templates/diary.html | 2 +- .../template-askama/templates/movie_detail.html | 2 +- .../adapters/template-askama/templates/profile.html | 4 ++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/adapters/template-askama/src/lib.rs b/crates/adapters/template-askama/src/lib.rs index f51e4bd..aaa3095 100644 --- a/crates/adapters/template-askama/src/lib.rs +++ b/crates/adapters/template-askama/src/lib.rs @@ -12,6 +12,18 @@ use domain::models::{ collections::Paginated, }; +mod filters { + #[askama::filter_fn] + pub fn poster_src(path: T, _env: &dyn askama::Values) -> askama::Result { + let p = path.to_string(); + if p.starts_with("http://") || p.starts_with("https://") { + Ok(p) + } else { + Ok(format!("/images/{}", p)) + } + } +} + struct PageItem { number: u32, is_current: bool, diff --git a/crates/adapters/template-askama/templates/activity_feed.html b/crates/adapters/template-askama/templates/activity_feed.html index d4c882e..8921bf1 100644 --- a/crates/adapters/template-askama/templates/activity_feed.html +++ b/crates/adapters/template-askama/templates/activity_feed.html @@ -26,7 +26,7 @@
{% if let Some(poster) = entry.movie().poster_path() %}
- +
{% endif %}
diff --git a/crates/adapters/template-askama/templates/diary.html b/crates/adapters/template-askama/templates/diary.html index ec01a65..5437948 100644 --- a/crates/adapters/template-askama/templates/diary.html +++ b/crates/adapters/template-askama/templates/diary.html @@ -5,7 +5,7 @@
{% if let Some(poster) = entry.movie().poster_path() %}
- +
{% endif %}
diff --git a/crates/adapters/template-askama/templates/movie_detail.html b/crates/adapters/template-askama/templates/movie_detail.html index 865822f..19ed138 100644 --- a/crates/adapters/template-askama/templates/movie_detail.html +++ b/crates/adapters/template-askama/templates/movie_detail.html @@ -5,7 +5,7 @@ {# ── Hero ── #}
{% if let Some(poster) = movie.poster_path() %} -
+
{% endif %}
diff --git a/crates/adapters/template-askama/templates/profile.html b/crates/adapters/template-askama/templates/profile.html index 5b94e98..8ec4016 100644 --- a/crates/adapters/template-askama/templates/profile.html +++ b/crates/adapters/template-askama/templates/profile.html @@ -115,7 +115,7 @@ {% for entry in month.entries %}
{% if let Some(poster) = entry.movie().poster_path() %} -
+
{% endif %}
{{ entry.movie().title().value() }} ({{ entry.movie().release_year().value() }})
@@ -183,7 +183,7 @@
{% if let Some(poster) = entry.movie().poster_path() %}
- +
{% endif %}