Browse Source

Create index page

master
Dylan Baker 5 years ago
parent
commit
fd3250f4e7
3 changed files with 30 additions and 8 deletions
  1. 0
    4
      src/gists.rs
  2. 3
    4
      src/routes.rs
  3. 27
    0
      templates/index.tera

+ 0
- 4
src/gists.rs View File

@@ -42,10 +42,6 @@ fn format_gist(filetype: Option<String>, body: String) -> String {
42 42
     )
43 43
 }
44 44
 
45
-pub fn all(connection: &PGC) -> QueryResult<Vec<Gist>> {
46
-    gists::table.load::<Gist>(&*connection)
47
-}
48
-
49 45
 pub fn get(connection: &PGC, id: i32) -> QueryResult<Gist> {
50 46
     gists::table.find(id).get_result::<Gist>(connection)
51 47
 }

+ 3
- 4
src/routes.rs View File

@@ -17,10 +17,9 @@ fn error_response(error: Error) -> Status {
17 17
 }
18 18
 
19 19
 #[get("/")]
20
-pub fn index(connection: DbConn) -> Result<Json<Vec<Gist>>, Status> {
21
-    gists::all(&connection)
22
-        .map(|gists| Json(gists))
23
-        .map_err(|error| error_response(error))
20
+pub fn index() -> Template {
21
+    let context: HashMap<&str, String> = HashMap::new();
22
+    Template::render("index", &context)
24 23
 }
25 24
 
26 25
 #[get("/gists/<id>")]

+ 27
- 0
templates/index.tera View File

@@ -0,0 +1,27 @@
1
+<html>
2
+  <head>
3
+    <title>bngl.ws</title>
4
+    <style>
5
+      .container {
6
+        margin: auto;
7
+        max-width: 500px;
8
+      }
9
+    </style>
10
+  </head>
11
+  <body>
12
+    <div class="container">
13
+      <h1>bngl.ws</h1>
14
+			<p>
15
+				bngl.ws is a pastebin service that you can access from the command
16
+				line. If you have
17
+				<a href="https://doc.rust-lang.org/cargo/getting-started/installation.html" target="_blank">
18
+				cargo</a> installed, you can install the CLI client by cloning the
19
+				<a href="https://git.sr.ht/~simulacrumparty/bnglws-client" target="_blank">client repo</a>
20
+				and running
21
+				<pre>cargo install --path .</pre>
22
+				Then, you can create snippets by running something like
23
+				<pre>echo 'Hello world' | bngl new --name "First snippet"</pre>
24
+			</p>
25
+    </div>
26
+  </body>
27
+</html>

Loading…
Cancel
Save