Compare commits

..

2 commits

Author SHA1 Message Date
7a6fdbef14
Round value placed in datatime attribute
Fixes #1
2024-11-24 17:19:41 +10:00
b5a249b756
Add alt tags to image attachments 2024-11-24 17:13:36 +10:00

View file

@ -1,5 +1,5 @@
use jiff::tz::TimeZone; use jiff::tz::TimeZone;
use jiff::Timestamp; use jiff::{Timestamp, Unit};
use pleroma::Activities; use pleroma::Activities;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::sync::OnceLock; use std::sync::OnceLock;
@ -227,7 +227,7 @@ markup::define! {
div[class="activity-content"] { div[class="activity-content"] {
a[href=MAPPINGS.get().unwrap().get(&activity.id).and_then(|url| url.as_ref().map(|url| url.path()))] { a[href=MAPPINGS.get().unwrap().get(&activity.id).and_then(|url| url.as_ref().map(|url| url.path()))] {
time[datetime=&activity.published] { @activity.human_published() } time[datetime=&activity.datetime()] { @activity.human_published() }
} }
@if let Some(in_reply_to) = &activity.in_reply_to { @if let Some(in_reply_to) = &activity.in_reply_to {
@ -259,7 +259,7 @@ markup::define! {
Attachment<'a>(attachment: &'a pleroma::activity::Attachment) { Attachment<'a>(attachment: &'a pleroma::activity::Attachment) {
@match attachment.media_type.as_str() { @match attachment.media_type.as_str() {
"image/gif" |"image/jpeg" | "image/png" => { "image/gif" |"image/jpeg" | "image/png" => {
img[src=&attachment.url, loading="lazy"]; img[src=&attachment.url, alt=&attachment.name, loading="lazy"];
} }
_ => { _ => {
a[href=&attachment.url] { @attachment.media_type " attachment" } a[href=&attachment.url] { @attachment.media_type " attachment" }
@ -285,6 +285,17 @@ impl pleroma::Activity {
published.strftime("%d %b %Y").to_string() published.strftime("%d %b %Y").to_string()
} }
/// datetime for `time` element
fn datetime(&self) -> String {
let published = self
.published
.parse::<Timestamp>()
.map(|ts| ts.round(Unit::Second).expect("rounding to succeeed"))
.expect("invalid published value");
published.to_string()
}
} }
impl pleroma::Actor { impl pleroma::Actor {