diff --git a/src/models/blogs.rs b/src/models/blogs.rs index 0ec72c4c..46117dcc 100644 --- a/src/models/blogs.rs +++ b/src/models/blogs.rs @@ -15,7 +15,7 @@ use models::instance::Instance; use schema::blogs; -#[derive(Queryable, Identifiable)] +#[derive(Queryable, Identifiable, Serialize)] pub struct Blog { pub id: i32, pub actor_id: String, diff --git a/src/models/instance.rs b/src/models/instance.rs index 1ccc0579..9b302dcb 100644 --- a/src/models/instance.rs +++ b/src/models/instance.rs @@ -5,7 +5,7 @@ use std::iter::Iterator; use models::users::User; use schema::{instances, users}; -#[derive(Identifiable, Queryable)] +#[derive(Identifiable, Queryable, Serialize)] pub struct Instance { pub id: i32, pub public_domain: String, diff --git a/src/models/posts.rs b/src/models/posts.rs index 7447d856..9d126df3 100644 --- a/src/models/posts.rs +++ b/src/models/posts.rs @@ -12,7 +12,7 @@ use models::users::User; use models::post_authors::PostAuthor; use schema::posts; -#[derive(Queryable, Identifiable)] +#[derive(Queryable, Identifiable, Serialize)] pub struct Post { pub id: i32, pub blog_id: i32, diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index ace2597b..faa378c3 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -14,8 +14,11 @@ use models::users::User; use utils; #[get("/~/", rank = 2)] -fn details(name: String) -> String { - format!("Welcome on ~{}", name) +fn details(name: String, conn: DbConn) -> Template { + let blog = Blog::find_by_actor_id(&*conn, name).unwrap(); + Template::render("blogs/details", json!({ + "blog": blog + })) } #[get("/~/", format = "application/activity+json", rank = 1)] diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 1a33d7c1..6e823726 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -8,13 +8,17 @@ use db_conn::DbConn; use models::instance::*; #[get("/")] -fn index(conn: DbConn) -> String { +fn index(conn: DbConn) -> Template { match Instance::get_local(&*conn) { Some(inst) => { - format!("Welcome on {}", inst.name) + Template::render("instance/index", json!({ + "instance": inst + })) } None => { - String::from("Not initialized") + Template::render("errors/500", json!({ + "error_message": "You need to configure your instance before using it." + })) } } } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 571f1b41..3b0e4dbd 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -16,10 +16,13 @@ use models::users::User; use utils; #[get("/~//", rank = 4)] -fn details(blog: String, slug: String, conn: DbConn) -> String { +fn details(blog: String, slug: String, conn: DbConn) -> Template { let blog = Blog::find_by_actor_id(&*conn, blog).unwrap(); let post = Post::find_by_slug(&*conn, slug).unwrap(); - format!("{} in {}", post.title, blog.title) + Template::render("posts/details", json!({ + "post": post, + "blog": blog + })) } #[get("/~/<_blog>/", rank = 3, format = "application/activity+json")] diff --git a/src/routes/user.rs b/src/routes/user.rs index 62d29033..49cdab9e 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -14,8 +14,8 @@ use models::instance::Instance; use models::users::*; #[get("/me")] -fn me(user: User) -> String { - format!("Logged in as {}", user.username.to_string()) +fn me(user: User) -> Redirect { + Redirect::to(format!("/@/{}", user.username).as_ref()) } #[get("/@/", rank = 2)] diff --git a/templates/blogs/details.tera b/templates/blogs/details.tera new file mode 100644 index 00000000..c875a1bb --- /dev/null +++ b/templates/blogs/details.tera @@ -0,0 +1,10 @@ +{% extends "base" %} + +{% block title %} +{{ blog.title }} +{% endblock title %} + +{% block content %} +

{{ blog.title }} (~{{ blog.actor_id }})

+

{{ blog.summary }}

+{% endblock content %} diff --git a/templates/errors/500.tera b/templates/errors/500.tera new file mode 100644 index 00000000..f72d88ac --- /dev/null +++ b/templates/errors/500.tera @@ -0,0 +1,6 @@ +{% extends "errors/base" %} + +{% block error %} +

Something broke on our side.

+

Sorry about that. If you think this is a bug, please report it.

+{% endblock error %} diff --git a/templates/errors/base.tera b/templates/errors/base.tera new file mode 100644 index 00000000..40b541bb --- /dev/null +++ b/templates/errors/base.tera @@ -0,0 +1,15 @@ +{% extends "base" %} + +{% block title %} +{{ error_message }} +{% endblock title %} + +{% block content %} +
+ {% block error %} + {% endblock error %} +

+ {{ error_message }} +

+
+{% endblock content %} diff --git a/templates/instance/index.tera b/templates/instance/index.tera new file mode 100644 index 00000000..5a304ca0 --- /dev/null +++ b/templates/instance/index.tera @@ -0,0 +1,9 @@ +{% extends "base" %} + +{% block title %} +{{ instance.name }} +{% endblock title %} + +{% block content %} +

Welcome on {{ instance.name }}

+{% endblock content %} diff --git a/templates/posts/details.tera b/templates/posts/details.tera new file mode 100644 index 00000000..1714bfed --- /dev/null +++ b/templates/posts/details.tera @@ -0,0 +1,15 @@ +{% extends "base" %} + +{% block title %} +{{ post.title }} +{% endblock title %} + +{% block content %} +

{{ post.title }}

+

Published in {{ blog.title }}

+
+

+ {{ post.content | safe }} +

+

License: {{ post.license }}

+{% endblock content %}