Prepublish only sets the publish time if one was not already specified

main
Pantonshire 4 years ago
parent 0a5d300e64
commit dacf9f0b53

@ -29,7 +29,9 @@ fn main() {
},
};
*source.header_mut().published_mut() = Utc::now();
if source.header().published().is_none() {
*source.header_mut().published_mut() = Some(Utc::now());
}
if let Err(err) = fs::write(&path, source.to_string()) {
eprintln!("failed to write {}: {}", path.to_string_lossy(), err);

@ -13,8 +13,7 @@ pub struct Header {
pub(super) author: ShString22,
#[serde(default)]
pub(super) tags: Vec<ShString22>,
#[serde(default = "crate::time::unix_epoch")]
pub(super) published: DateTime<Utc>,
pub(super) published: Option<DateTime<Utc>>,
}
impl Header {
@ -68,13 +67,13 @@ impl Header {
#[inline]
#[must_use]
pub fn published(&self) -> DateTime<Utc> {
pub fn published(&self) -> Option<DateTime<Utc>> {
self.published
}
#[inline]
#[must_use]
pub fn published_mut(&mut self) -> &mut DateTime<Utc> {
pub fn published_mut(&mut self) -> &mut Option<DateTime<Utc>> {
&mut self.published
}
}

@ -16,7 +16,7 @@ pub struct RenderedPost {
uuid: Uuid,
id: Id,
header: Header,
updated: DateTime<Utc>,
updated: Option<DateTime<Utc>>,
html: Markup,
}
@ -50,7 +50,7 @@ impl RenderedPost {
uuid,
id,
header: source.header,
updated: updated.unwrap_or_else(unix_epoch),
updated,
html: render_markdown(code_renderer, &source.markdown),
})
}
@ -101,12 +101,14 @@ impl RenderedPost {
#[must_use]
pub fn published(&self) -> DateTime<Utc> {
self.header.published()
.unwrap_or_else(unix_epoch)
}
#[inline]
#[must_use]
pub fn updated(&self) -> DateTime<Utc> {
self.updated
.unwrap_or_else(unix_epoch)
}
#[inline]

Loading…
Cancel
Save