feat(backend/post) new id strategy

This commit is contained in:
lumither committed 2024-05-04 15:55:00 +08:00
1 parent 4e71a1ccf0
commit 131789bf83
1 file changed
+7 -1
+7 -1
View File
@@ -2,6 +2,7 @@ use std::{env, fs};
use std::error::Error;
use std::process::Command;
use std::str;
use std::str::FromStr;
use chrono::{NaiveDate, NaiveDateTime, Utc};
use uuid::Uuid;
@@ -14,6 +15,11 @@ impl Post {
let md_content = fs::read_to_string(&path)?;
let meta = parse_meta(&md_content);
let post_id = match meta.get("id") {
None => { Uuid::new_v4() }
Some(id) => { Uuid::from_str(id.as_str()).expect("Invalid UUID String") }
};
let title = match meta.get("title") {
None => "Title Not Found".to_string(),
Some(title) => title.to_owned(),
@@ -53,7 +59,7 @@ impl Post {
};
Ok(Post {
post_id: Uuid::new_v4(),
post_id,
title,
summary,
content: md_content,