Prepublish only sets the publish time if one was not already specified
This commit is contained in:
1 parent
0a5d300e64
commit
dacf9f0b53
3 files changed
+10
-7
No files matched your search
@@ -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()) {
|
if let Err(err) = fs::write(&path, source.to_string()) {
|
||||||
eprintln!("failed to write {}: {}", path.to_string_lossy(), err);
|
eprintln!("failed to write {}: {}", path.to_string_lossy(), err);
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ pub struct Header {
|
|||||||
pub(super) author: ShString22,
|
pub(super) author: ShString22,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub(super) tags: Vec<ShString22>,
|
pub(super) tags: Vec<ShString22>,
|
||||||
#[serde(default = "crate::time::unix_epoch")]
|
pub(super) published: Option<DateTime<Utc>>,
|
||||||
pub(super) published: DateTime<Utc>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Header {
|
impl Header {
|
||||||
@@ -68,13 +67,13 @@ impl Header {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn published(&self) -> DateTime<Utc> {
|
pub fn published(&self) -> Option<DateTime<Utc>> {
|
||||||
self.published
|
self.published
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn published_mut(&mut self) -> &mut DateTime<Utc> {
|
pub fn published_mut(&mut self) -> &mut Option<DateTime<Utc>> {
|
||||||
&mut self.published
|
&mut self.published
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub struct RenderedPost {
|
|||||||
uuid: Uuid,
|
uuid: Uuid,
|
||||||
id: Id,
|
id: Id,
|
||||||
header: Header,
|
header: Header,
|
||||||
updated: DateTime<Utc>,
|
updated: Option<DateTime<Utc>>,
|
||||||
html: Markup,
|
html: Markup,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ impl RenderedPost {
|
|||||||
uuid,
|
uuid,
|
||||||
id,
|
id,
|
||||||
header: source.header,
|
header: source.header,
|
||||||
updated: updated.unwrap_or_else(unix_epoch),
|
updated,
|
||||||
html: render_markdown(code_renderer, &source.markdown),
|
html: render_markdown(code_renderer, &source.markdown),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -101,12 +101,14 @@ impl RenderedPost {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn published(&self) -> DateTime<Utc> {
|
pub fn published(&self) -> DateTime<Utc> {
|
||||||
self.header.published()
|
self.header.published()
|
||||||
|
.unwrap_or_else(unix_epoch)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn updated(&self) -> DateTime<Utc> {
|
pub fn updated(&self) -> DateTime<Utc> {
|
||||||
self.updated
|
self.updated
|
||||||
|
.unwrap_or_else(unix_epoch)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
Reference in new issue
Block a user