aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs64
1 files changed, 5 insertions, 59 deletions
diff --git a/src/main.rs b/src/main.rs
index 63a5386..ed34713 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,60 +1,11 @@
-pub mod router;
use std::convert::Infallible;
-use rust_embed::RustEmbed;
-use std::{env, str};
+use std::{env};
use std::net::SocketAddr;
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
-use sailfish::TemplateOnce;
-use ::router::Router;
-
-struct PostEntry {
- title: String,
- file: String,
-}
-
-#[derive(TemplateOnce)]
-#[template(path = "index.html")]
-struct IndexTemplate {
- posts: Vec<PostEntry>,
-}
-
-#[derive(TemplateOnce)]
-#[template(path = "post.html")]
-struct PostTemplate {
- content: String,
-}
-
-#[derive(RustEmbed)]
-#[folder = "content/posts/"]
-struct PostAsset;
-
-
-fn get_file_content(path: &str) -> String {
- let buffer = PostAsset::get(path)
- .unwrap()
- .data
- .into_owned();
-
- return String::from_utf8(buffer).unwrap();
-}
-
-fn get_post_entry(path: &String) -> PostEntry {
- let sub_title = str::replace(path, "_", " ");
- let title = str::replace(sub_title.as_str(), ".html", "");
- PostEntry {
- title: String::from(title),
- file: String::from(path),
- }
-}
-
-fn get_post_title() -> Vec<PostEntry> {
- PostAsset::iter()
- .map(|e| format!("{}", e))
- .map(|e| get_post_entry(&e))
- .collect()
-}
+use macroblog::router::Router;
+use macroblog::blog::{render_index_page, render_post_page};
async fn not_found() -> Result<Response<Body>, Infallible> {
@@ -67,10 +18,7 @@ async fn not_found() -> Result<Response<Body>, Infallible> {
async fn index() -> Result<Response<Body>, Infallible> {
- let files = get_post_title();
- let body = IndexTemplate { posts: files }
- .render_once()
- .unwrap();
+ let body = render_index_page();
let resp: Response<Body> = Response::builder()
.status(200)
@@ -83,9 +31,7 @@ async fn index() -> Result<Response<Body>, Infallible> {
async fn post(path: &String) -> Result<Response<Body>, Infallible> {
- let body = PostTemplate { content: get_file_content(path) }
- .render_once()
- .unwrap();
+ let body = render_post_page(path);
let resp: Response<Body> = Response::builder()
.status(200)