Sfoglia il codice sorgente

Move to root path, not admin

master
Dylan Baker 3 anni fa
parent
commit
7362b898f3
3 ha cambiato i file con 6 aggiunte e 6 eliminazioni
  1. 4
    4
      src/main.rs
  2. 2
    2
      templates/index.html
  3. 0
    0
      templates/layout.html

+ 4
- 4
src/main.rs Vedi File

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

templates/admin/index.html → templates/index.html Vedi File

1
-{% extends "admin/layout.html" %} {% block content %}
1
+{% extends "layout.html" %} {% block content %}
2
 <h1 class="heading">Admin</h1>
2
 <h1 class="heading">Admin</h1>
3
-<form class="form" method="POST" action="/admin/posts">
3
+<form class="form" method="POST" action="/posts">
4
   <input type="hidden" name="id" />
4
   <input type="hidden" name="id" />
5
   <input type="hidden" name="date" />
5
   <input type="hidden" name="date" />
6
   <div class="form__field">
6
   <div class="form__field">

templates/admin/layout.html → templates/layout.html Vedi File


Loading…
Annulla
Salva