|
@@ -1,4 +1,5 @@
|
1
|
1
|
use std::env;
|
|
2
|
+use std::ffi::OsStr;
|
2
|
3
|
use std::fs::{read_dir, File};
|
3
|
4
|
use std::io::prelude::*;
|
4
|
5
|
use std::io::{Error, ErrorKind};
|
|
@@ -57,9 +58,12 @@ async fn read_all_posts() -> Result<Vec<Post>, Error> {
|
57
|
58
|
|
58
|
59
|
for file in read_dir(path)? {
|
59
|
60
|
let file = file?;
|
60
|
|
- let contents = read_to_string(file.path()).await?;
|
61
|
|
- let post: Post = serde_json::from_str(&contents)?;
|
62
|
|
- posts.push(post);
|
|
61
|
+ if let Some("json") = file.path().extension().and_then(OsStr::to_str) {
|
|
62
|
+ let contents = read_to_string(file.path()).await?;
|
|
63
|
+ let mut post: Post = serde_json::from_str(&contents)?;
|
|
64
|
+ post.body = post.body.replace("\n", "<br>");
|
|
65
|
+ posts.push(post);
|
|
66
|
+ }
|
63
|
67
|
}
|
64
|
68
|
|
65
|
69
|
Ok(posts)
|
|
@@ -101,6 +105,7 @@ async fn main() -> std::io::Result<()> {
|
101
|
105
|
let mut post: Post = req.body_form().await?;
|
102
|
106
|
post.id = Uuid::new_v4().to_string();
|
103
|
107
|
post.date = Local::now().date().naive_local().to_string();
|
|
108
|
+ post.body = post.body.trim().to_owned();
|
104
|
109
|
post.save()?;
|
105
|
110
|
Ok(tide::Redirect::new("/admin"))
|
106
|
111
|
});
|