mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-05-09 18:16:43 -07: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">
|
<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>
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue