Make image timestamps even more readable

This commit is contained in:
Zoey 2022-12-16 04:23:01 -08:00
parent dd25ebfb71
commit 2114b86f65
No known key found for this signature in database
GPG key ID: 0E87B6A5795E040B
2 changed files with 18 additions and 3 deletions

View file

@ -1,6 +1,6 @@
<div class="image-full"> <div class="image-full">
<h1 class="title">{{title}}</h1> <h1 class="title">{{title}}</h1>
<span class="timestamp">{{timestamp}}</span> <span class="timestamp">Published {{timestamp}}</span>
<img class="image-actual" src="{{src}}" alt="{{alt}}"> <img class="image-actual" src="{{src}}" alt="{{alt}}">
{{#if desc}} {{#if desc}}
<p>{{desc}}</p> <p>{{desc}}</p>

View file

@ -6,7 +6,7 @@ use std::{
use anyhow::Context; use anyhow::Context;
use itertools::Itertools; use itertools::Itertools;
use rss::{validation::Validate, ChannelBuilder, ItemBuilder}; use rss::{validation::Validate, ChannelBuilder, ItemBuilder};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize, Serializer};
use time::{format_description::well_known::Rfc2822, OffsetDateTime}; use time::{format_description::well_known::Rfc2822, OffsetDateTime};
use url::Url; use url::Url;
@ -275,10 +275,25 @@ struct ImageTemplateData<'i> {
/// The image's ID. /// The image's ID.
id: &'i str, id: &'i str,
/// The image's timestamp. (Duplicated to change the serialization method.) /// The image's timestamp. (Duplicated to change the serialization method.)
#[serde(serialize_with = "time::serde::rfc2822::serialize")] #[serde(serialize_with = "ImageTemplateData::timestamp_formatter")]
timestamp: OffsetDateTime, timestamp: OffsetDateTime,
} }
impl<'i> ImageTemplateData<'i> {
fn timestamp_formatter<S>(timestamp: &OffsetDateTime, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let out = timestamp
.format(
&time::format_description::parse("[weekday], [month repr:long] [day], [year]")
.expect("Should never fail"),
)
.expect("Should never fail");
serializer.serialize_str(&out)
}
}
/// Template data for image lists. /// Template data for image lists.
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
struct ImageListTemplateData<'i> { struct ImageListTemplateData<'i> {