mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(backend/post) new id strategy
This commit is contained in:
1 file changed
+7
-1
@@ -2,6 +2,7 @@ use std::{env, fs};
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use chrono::{NaiveDate, NaiveDateTime, Utc};
|
use chrono::{NaiveDate, NaiveDateTime, Utc};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -14,6 +15,11 @@ impl Post {
|
|||||||
let md_content = fs::read_to_string(&path)?;
|
let md_content = fs::read_to_string(&path)?;
|
||||||
let meta = parse_meta(&md_content);
|
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") {
|
let title = match meta.get("title") {
|
||||||
None => "Title Not Found".to_string(),
|
None => "Title Not Found".to_string(),
|
||||||
Some(title) => title.to_owned(),
|
Some(title) => title.to_owned(),
|
||||||
@@ -53,7 +59,7 @@ impl Post {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(Post {
|
Ok(Post {
|
||||||
post_id: Uuid::new_v4(),
|
post_id,
|
||||||
title,
|
title,
|
||||||
summary,
|
summary,
|
||||||
content: md_content,
|
content: md_content,
|
||||||
|
|||||||
Reference in new issue
Block a user