introducing templating inheritance and macros
This commit is contained in:
parent
7fe997acff
commit
2e7a81d7c7
11 changed files with 206 additions and 230 deletions
|
@ -26,7 +26,8 @@ article {
|
|||
}
|
||||
|
||||
.post-link {
|
||||
padding-right: 20px;
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
|
@ -39,6 +40,12 @@ article {
|
|||
|
||||
.post-body {
|
||||
padding-top: 1rem;
|
||||
margin-left: 2rem;
|
||||
}
|
||||
|
||||
.submit-box {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#submit-form {
|
||||
|
|
|
@ -1,36 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
{% extends "base.html" %}
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta property="og:title" content="{{ username }}' site'" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<title>Submit post</title>
|
||||
<meta property="og:title" content="{{ username }} site" />
|
||||
{% endblock head %}
|
||||
|
||||
<title>{{ username }}' site</title>
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hi, I'm {{ username }}</h1>
|
||||
<p style="text-align: right">
|
||||
{% block content %}
|
||||
<h1>Hi, I'm {{ username }}</h1>
|
||||
<p style="text-align: right">
|
||||
<a href="/">Back to the blog</a>
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
This is my blog.
|
||||
|
||||
{% if email %}
|
||||
If you have questions or input for me please send me an E-Mail to <img class="social-icon"
|
||||
src="/static/social-icons/mail.png" /> {{ email }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<br>
|
||||
<p>
|
||||
<ul style="list-style: none;">
|
||||
</p>
|
||||
<br>
|
||||
<p>
|
||||
<ul style="list-style: none;">
|
||||
{% if github_account %}
|
||||
<li><img class="social-icon" src="/static/social-icons/github.ico"><a
|
||||
href="https://github.com/{{ github_account }}"> {{ github_account }}</a></li>
|
||||
<li><img class="social-icon" src="/static/social-icons/github.ico"><a href="https://github.com/{{ github_account }}">
|
||||
{{ github_account }}</a></li>
|
||||
{% endif %}
|
||||
{% if twitter_account %}
|
||||
<li><img class="social-icon" src="/static/social-icons/twitter.ico"><a
|
||||
|
@ -48,8 +42,6 @@
|
|||
<li><img class="social-icon" src="/static/social-icons/discord.ico"><a href="https://discord.com/"> {{
|
||||
discord_account }}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</ul>
|
||||
</p>
|
||||
{% endblock content %}
|
11
site/content/templates/article.html.macro
Normal file
11
site/content/templates/article.html.macro
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% macro article(id, title, body, publish_date) %}
|
||||
<article>
|
||||
<div class="post-content">
|
||||
<a href="/id/{{ id }}" class="post-link">
|
||||
<h2 class="post-title">{{ title }}</h2>
|
||||
</a>
|
||||
<sub class="post-publish-date"> {{ publish_date | date(format="%Y-%m-%d at %H:%M") }}</sub>
|
||||
<p class="post-body">{{ body }}</p>
|
||||
</div>
|
||||
</article>
|
||||
{% endmacro article %}
|
18
site/content/templates/base.html
Normal file
18
site/content/templates/base.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
{% block head %}
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% endblock head %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">{% block content %}{% endblock content %}</div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,35 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta property="og:title" content="{{ username }}' blog" />
|
||||
<meta property="og:description" content="List of all posts" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% extends "base.html" %}
|
||||
{% import "article.html.macro" as article_macro %}
|
||||
|
||||
<title> All posts </title>
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico"/>
|
||||
</head>
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<meta property="og:title" content="{{ username }}' blog" />
|
||||
<meta property="og:description" content="List of all posts" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
<title> All posts </title>
|
||||
{% endblock head %}
|
||||
|
||||
<body>
|
||||
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }}' blog</a></h1>
|
||||
<p style="text-align: right">
|
||||
|
||||
{% block content %}
|
||||
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }} blog</a></h1>
|
||||
<p style="text-align: right">
|
||||
<a href="/about">About</a>
|
||||
<a href="/">Last 5 posts</a>
|
||||
</p>
|
||||
<ul>
|
||||
</p>
|
||||
<ul>
|
||||
{% for post in posts %}
|
||||
<article>
|
||||
<div>
|
||||
<a href="/id/{{ post.id }}" class="post-link">[link]</a>
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<h2 class="post-title">{{ post.title }}</h2>
|
||||
<sub class="post-publish-date"> {{ post.publish_date | date(format="%Y-%m-%d at %H:%M") }}</sub>
|
||||
</div>
|
||||
</article>
|
||||
{{ article_macro::article(id=post.id,title=post.title,body=post.body,publish_date=post.publish_date) }}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
</ul>
|
||||
|
||||
{% endblock content %}
|
|
@ -1,35 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta property="og:title" content=" {{ post.title }} | {{ username }}' blog" />
|
||||
<meta property="og:description" content="{{ post.body | striptags }}" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% extends "base.html" %}
|
||||
|
||||
<title> {{ post.title }} | {{ username }}' blog </title>
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico"/>
|
||||
</head>
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<meta property="og:title" content=" {{ post.title }} | {{ username }}' blog" />
|
||||
<meta property="og:description" content="{{ post.body | striptags }}" />
|
||||
<title> {{ post.title }} | {{ username }}' blog </title>
|
||||
{% endblock head %}
|
||||
|
||||
<body>
|
||||
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }}' blog</a></h1>
|
||||
<p style="text-align: right">
|
||||
{% block content %}
|
||||
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }} blog</a></h1>
|
||||
<p style="text-align: right">
|
||||
<a href="/">Home</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="/all">All Posts</a>
|
||||
</p>
|
||||
<ul>
|
||||
</p>
|
||||
<ul>
|
||||
<article>
|
||||
<div>
|
||||
<a href="/id/{{ post.id }}" class="post-link">[link]</a>
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<a href="/id/{{ post.id }}" class="post-link">
|
||||
<h2 class="post-title">{{ post.title }}</h2>
|
||||
</a>
|
||||
<sub class="post-publish-date"> {{ post.publish_date | date(format="%Y-%m-%d at %H:%M") }}</sub>
|
||||
<p class="post-body">{{ post.body }}</p>
|
||||
</div>
|
||||
</article>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
</ul>
|
||||
{% endblock content %}
|
|
@ -1,38 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
{% extends "base.html" %}
|
||||
{% import "article.html.macro" as article_macro %}
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta property="og:title" content="{{ username }}' blog" />
|
||||
<meta property="og:description" content="Last 5 posts" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<meta property="og:title" content="{{ username }}' blog" />
|
||||
<meta property="og:description" content="Last 5 posts" />
|
||||
<title> {{ username }} blog </title>
|
||||
{% endblock head %}
|
||||
|
||||
<title> {{ username }}' blog </title>
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }} blog</a></h1>
|
||||
<p style="text-align: right">
|
||||
{% block content %}
|
||||
<h1><a href="/" class="post-link">{{ username }} blog</a></h1>
|
||||
<p style="text-align: right">
|
||||
<a href="/about">About</a>
|
||||
<a href="/all">All Posts</a>
|
||||
</p>
|
||||
<ul>
|
||||
</p>
|
||||
<ul>
|
||||
{% for post in posts %}
|
||||
<article>
|
||||
<div>
|
||||
<a href="/id/{{ post.id }}" class="post-link">[link]</a>
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<h2 class="post-title">{{ post.title }}</h2>
|
||||
<sub class="post-publish-date"> {{ post.publish_date | date(format="%Y-%m-%d at %H:%M") }}</sub>
|
||||
<p class="post-body">{{ post.body }}</p>
|
||||
</div>
|
||||
</article>
|
||||
{{ article_macro::article(id=post.id,title=post.title,body=post.body,publish_date=post.publish_date) }}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</ul>
|
||||
{% endblock content %}
|
|
@ -1,43 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
{% extends "base.html" %}
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta property="og:title" content="Edit '{{ title }}'" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<title>Edit '{{ title }}'</title>
|
||||
<meta property="og:title" content="Edit '{{ title }}'" />
|
||||
{% endblock head %}
|
||||
|
||||
<title>Edit '{{ title }}'</title>
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="cookie-block" hidden>
|
||||
{% block content %}
|
||||
<form id="submit-form" action="/api/blog/posts/edit/{{ id }}" method=POST>
|
||||
<label for="token">Password</label>
|
||||
</br>
|
||||
<br />
|
||||
<input id="token" type="password" name="token">
|
||||
</div>
|
||||
|
||||
<form id="submit-form" action="/api/blog/posts/edit/{{ id }}" method=POST>
|
||||
<input class="token" type="text" name="token" hidden>
|
||||
<br />
|
||||
<label for="title">Title</label>
|
||||
<textarea id="submit-title" type="text" name="title">{{ title }}</textarea>
|
||||
<br>
|
||||
<br />
|
||||
<label for="submit-body">Content</label>
|
||||
<textarea id="submit-body" type="text" name="body">{{ body }}</textarea>
|
||||
<br>
|
||||
<br />
|
||||
<button id="submit-button" type="submit">Edit post</button>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<form action="/api/blog/posts/hide/{{ id }}" method="POST">
|
||||
<form action="/api/blog/posts/hide/{{ id }}" method="POST">
|
||||
<input class="token" type="text" name="token" hidden>
|
||||
<button type="submit">Hide post</button>
|
||||
</form>
|
||||
<form action="/api/blog/posts/delete/{{ id }}" method="POST">
|
||||
</form>
|
||||
<form action="/api/blog/posts/delete/{{ id }}" method="POST">
|
||||
<input class="token" type="text" name="token" hidden>
|
||||
<button type="submit">Delete post</button>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -1,34 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
{% extends "base.html" %}
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta property="og:title" content="Submit post" />
|
||||
<meta property="og:image" content="/static/site-image.png" />
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<title>Submit post</title>
|
||||
<meta property="og:title" content="Submit post" />
|
||||
{% endblock head %}
|
||||
|
||||
<title>Submit post</title>
|
||||
<link rel="stylesheet" href="/static/css/blog.css">
|
||||
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="cookie-block" hidden>
|
||||
<label for="token">Password</label>
|
||||
<br />
|
||||
<input id="token" type="password" name="token">
|
||||
</div>
|
||||
|
||||
<form id="submit-form" action="/api/blog/create" method=POST>
|
||||
<input class="token" type="text" name="token" hidden>
|
||||
{% block content %}
|
||||
<form id="submit-form" action="/api/blog/create" method=POST>
|
||||
<label for="title">Title</label>
|
||||
<textarea id="submit-title" type="text" name="title">{{ title }}</textarea>
|
||||
<br>
|
||||
<br />
|
||||
<label for="submit-body">Content</label>
|
||||
<textarea id="submit-body" type="text" name="body">{{ body }}</textarea>
|
||||
<br>
|
||||
<br />
|
||||
<div class="submit-box">
|
||||
<div>
|
||||
<label for="token">Password</label>
|
||||
<input id="token" type="password" name="token">
|
||||
</div>
|
||||
<button id="submit-button" type="submit">Submit</button>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -26,7 +26,7 @@ async fn blog_create_post(form: Form<NewPostForm>) -> impl Responder {
|
|||
}
|
||||
|
||||
HttpResponse::MovedPermanently()
|
||||
.insert_header(("LOCATION", "/blog"))
|
||||
.insert_header(("LOCATION", "/"))
|
||||
.finish()
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ async fn blog_edit_post(post_id: web::Path<String>, form: Form<NewPostForm>) ->
|
|||
}
|
||||
|
||||
return HttpResponse::MovedPermanently()
|
||||
.insert_header(("LOCATION", "/blog"))
|
||||
.insert_header(("LOCATION", "/"))
|
||||
.finish();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ async fn blog_delete_post(
|
|||
}
|
||||
|
||||
return HttpResponse::MovedPermanently()
|
||||
.insert_header(("LOCATION", "/blog"))
|
||||
.insert_header(("LOCATION", "/"))
|
||||
.finish();
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ async fn blog_hide_post(post_id: web::Path<String>, form: Form<BlogActionForm>)
|
|||
}
|
||||
|
||||
return HttpResponse::MovedPermanently()
|
||||
.insert_header(("LOCATION", "/blog"))
|
||||
.insert_header(("LOCATION", "/"))
|
||||
.finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ async fn main() -> std::io::Result<()> {
|
|||
Tera::new(format!("{}{}", CONFIG.root_path, "/templates/*").as_str()).unwrap();
|
||||
tera.autoescape_on(vec![".sql"]);
|
||||
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info"));
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("debug"));
|
||||
|
||||
App::new()
|
||||
.app_data(Data::new(tera))
|
||||
|
|
Loading…
Reference in a new issue