Add actual templates for everything
This commit is contained in:
parent
ae60d5961c
commit
292f4d6b27
@ -15,7 +15,7 @@ use models::instance::Instance;
|
|||||||
use schema::blogs;
|
use schema::blogs;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable, Serialize)]
|
||||||
pub struct Blog {
|
pub struct Blog {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub actor_id: String,
|
pub actor_id: String,
|
||||||
|
@ -5,7 +5,7 @@ use std::iter::Iterator;
|
|||||||
use models::users::User;
|
use models::users::User;
|
||||||
use schema::{instances, users};
|
use schema::{instances, users};
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable)]
|
#[derive(Identifiable, Queryable, Serialize)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub public_domain: String,
|
pub public_domain: String,
|
||||||
|
@ -12,7 +12,7 @@ use models::users::User;
|
|||||||
use models::post_authors::PostAuthor;
|
use models::post_authors::PostAuthor;
|
||||||
use schema::posts;
|
use schema::posts;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable)]
|
#[derive(Queryable, Identifiable, Serialize)]
|
||||||
pub struct Post {
|
pub struct Post {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub blog_id: i32,
|
pub blog_id: i32,
|
||||||
|
@ -14,8 +14,11 @@ use models::users::User;
|
|||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
#[get("/~/<name>", rank = 2)]
|
#[get("/~/<name>", rank = 2)]
|
||||||
fn details(name: String) -> String {
|
fn details(name: String, conn: DbConn) -> Template {
|
||||||
format!("Welcome on ~{}", name)
|
let blog = Blog::find_by_actor_id(&*conn, name).unwrap();
|
||||||
|
Template::render("blogs/details", json!({
|
||||||
|
"blog": blog
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/~/<name>", format = "application/activity+json", rank = 1)]
|
#[get("/~/<name>", format = "application/activity+json", rank = 1)]
|
||||||
|
@ -8,13 +8,17 @@ use db_conn::DbConn;
|
|||||||
use models::instance::*;
|
use models::instance::*;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index(conn: DbConn) -> String {
|
fn index(conn: DbConn) -> Template {
|
||||||
match Instance::get_local(&*conn) {
|
match Instance::get_local(&*conn) {
|
||||||
Some(inst) => {
|
Some(inst) => {
|
||||||
format!("Welcome on {}", inst.name)
|
Template::render("instance/index", json!({
|
||||||
|
"instance": inst
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
String::from("Not initialized")
|
Template::render("errors/500", json!({
|
||||||
|
"error_message": "You need to configure your instance before using it."
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,13 @@ use models::users::User;
|
|||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
#[get("/~/<blog>/<slug>", rank = 4)]
|
#[get("/~/<blog>/<slug>", 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 blog = Blog::find_by_actor_id(&*conn, blog).unwrap();
|
||||||
let post = Post::find_by_slug(&*conn, slug).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>/<slug>", rank = 3, format = "application/activity+json")]
|
#[get("/~/<_blog>/<slug>", rank = 3, format = "application/activity+json")]
|
||||||
|
@ -14,8 +14,8 @@ use models::instance::Instance;
|
|||||||
use models::users::*;
|
use models::users::*;
|
||||||
|
|
||||||
#[get("/me")]
|
#[get("/me")]
|
||||||
fn me(user: User) -> String {
|
fn me(user: User) -> Redirect {
|
||||||
format!("Logged in as {}", user.username.to_string())
|
Redirect::to(format!("/@/{}", user.username).as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/@/<name>", rank = 2)]
|
#[get("/@/<name>", rank = 2)]
|
||||||
|
10
templates/blogs/details.tera
Normal file
10
templates/blogs/details.tera
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ blog.title }}
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{{ blog.title }} (~{{ blog.actor_id }})</h1>
|
||||||
|
<p>{{ blog.summary }}</p>
|
||||||
|
{% endblock content %}
|
6
templates/errors/500.tera
Normal file
6
templates/errors/500.tera
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "errors/base" %}
|
||||||
|
|
||||||
|
{% block error %}
|
||||||
|
<h1>Something broke on our side.</h1>
|
||||||
|
<h2>Sorry about that. If you think this is a bug, please report it.</h2>
|
||||||
|
{% endblock error %}
|
15
templates/errors/base.tera
Normal file
15
templates/errors/base.tera
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ error_message }}
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main class="error">
|
||||||
|
{% block error %}
|
||||||
|
{% endblock error %}
|
||||||
|
<p>
|
||||||
|
{{ error_message }}
|
||||||
|
</p>
|
||||||
|
</main>
|
||||||
|
{% endblock content %}
|
9
templates/instance/index.tera
Normal file
9
templates/instance/index.tera
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ instance.name }}
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Welcome on {{ instance.name }}</h1>
|
||||||
|
{% endblock content %}
|
15
templates/posts/details.tera
Normal file
15
templates/posts/details.tera
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ post.title }}
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{{ post.title }}</h1>
|
||||||
|
<p>Published in {{ blog.title }}</p>
|
||||||
|
<hr>
|
||||||
|
<p>
|
||||||
|
{{ post.content | safe }}
|
||||||
|
</p>
|
||||||
|
<p>License: {{ post.license }}</p>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user