mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 18:36:21 +00:00
feat(backend/database/post) add first_update
This commit is contained in:
4 files changed
+39
-23
No files matched your search
@@ -12,6 +12,7 @@ pub struct Post {
|
||||
pub summary: String,
|
||||
pub content: String,
|
||||
pub last_update: NaiveDateTime,
|
||||
pub first_update: NaiveDateTime,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::error::Error;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use chrono::{NaiveDate, NaiveDateTime, Utc};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::markdown::meta::parse_meta;
|
||||
@@ -44,12 +44,21 @@ impl Post {
|
||||
Utc::now().naive_utc()
|
||||
};
|
||||
|
||||
let first_update: NaiveDateTime = match meta.get("date") {
|
||||
None => Utc::now().naive_utc(),
|
||||
Some(date) => NaiveDateTime::from(
|
||||
NaiveDate::parse_from_str(date, "%Y-%m-%d%z")
|
||||
.expect("Failed to parse first_update time"),
|
||||
),
|
||||
};
|
||||
|
||||
Ok(Post {
|
||||
post_id: Uuid::new_v4(),
|
||||
title,
|
||||
summary,
|
||||
content: md_content,
|
||||
last_update,
|
||||
first_update,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user