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

This commit is contained in:
Pantonshire committed 2022-06-05 09:46:32 +01:00
1 parent 0a5d300e64
commit dacf9f0b53
3 files changed
+10 -7

No files matched your search

+3 -1
View File
@@ -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);
+3 -4
View File
@@ -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
}
}
+4 -2
View File
@@ -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]