|
@@ -91,23 +91,23 @@ async fn main() -> std::io::Result<()> {
|
91
|
91
|
Ok(res)
|
92
|
92
|
}));
|
93
|
93
|
|
94
|
|
- app.at("/admin").get(|_| async {
|
|
94
|
+ app.at("/").get(|_| async {
|
95
|
95
|
let tera = Tera::new("templates/**/*.html")?;
|
96
|
96
|
let posts = read_all_posts().await?;
|
97
|
97
|
let mut context = Context::new();
|
98
|
98
|
context.insert("posts", &posts);
|
99
|
|
- let html = tera.render("admin/index.html", &context)?;
|
|
99
|
+ let html = tera.render("index.html", &context)?;
|
100
|
100
|
Ok(Body::from_string(html))
|
101
|
101
|
});
|
102
|
102
|
|
103
|
|
- app.at("/admin/posts")
|
|
103
|
+ app.at("/posts")
|
104
|
104
|
.post(|mut req: tide::Request<()>| async move {
|
105
|
105
|
let mut post: Post = req.body_form().await?;
|
106
|
106
|
post.id = Uuid::new_v4().to_string();
|
107
|
107
|
post.date = Local::now().date().naive_local().to_string();
|
108
|
108
|
post.body = post.body.trim().to_owned();
|
109
|
109
|
post.save()?;
|
110
|
|
- Ok(tide::Redirect::new("/admin"))
|
|
110
|
+ Ok(tide::Redirect::new("/"))
|
111
|
111
|
});
|
112
|
112
|
|
113
|
113
|
app.listen("127.0.0.1:8080").await?;
|