mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-01-18 11:47:01 -08:00
Make image timestamps even more readable
This commit is contained in:
parent
80be46962d
commit
c44afa17c9
2 changed files with 18 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
<div class="image-full">
|
||||
<h1 class="title">{{title}}</h1>
|
||||
<span class="timestamp">{{timestamp}}</span>
|
||||
<span class="timestamp">Published {{timestamp}}</span>
|
||||
<img class="image-actual" src="{{src}}" alt="{{alt}}">
|
||||
{{#if desc}}
|
||||
<p>{{desc}}</p>
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
use anyhow::Context;
|
||||
use itertools::Itertools;
|
||||
use rss::{validation::Validate, ChannelBuilder, ItemBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use time::{format_description::well_known::Rfc2822, OffsetDateTime};
|
||||
use url::Url;
|
||||
|
||||
|
@ -275,10 +275,25 @@ struct ImageTemplateData<'i> {
|
|||
/// The image's ID.
|
||||
id: &'i str,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
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.
|
||||
#[derive(Debug, Serialize)]
|
||||
struct ImageListTemplateData<'i> {
|
||||
|
|
Loading…
Add table
Reference in a new issue