Update 2024 #1

Open
mtrx wants to merge 11 commits from update-2024 into main
11 changed files with 206 additions and 230 deletions
Showing only changes of commit 2e7a81d7c7 - Show all commits

View file

@ -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 {

View file

@ -1,18 +1,12 @@
<!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>
{% block content %}
<h1>Hi, I'm {{ username }}</h1>
<p style="text-align: right">
<a href="/">Back to the blog</a>
@ -29,8 +23,8 @@
<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
@ -50,6 +44,4 @@
{% endif %}
</ul>
</p>
</body>
</html>
{% endblock content %}

View 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 %}

View 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>

View file

@ -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">
{% extends "base.html" %}
{% import "article.html.macro" as article_macro %}
{% 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>
<link rel="stylesheet" href="/static/css/blog.css">
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico"/>
</head>
{% endblock head %}
<body>
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }}' blog</a></h1>
{% 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>
{% 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>
{% endblock content %}

View file

@ -1,19 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% extends "base.html" %}
{% block head %}
{{ super() }}
<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" />
<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>
{% endblock head %}
<body>
<h1><a href="/" class="post-link" style="text-decoration:none;color:black;">{{ username }}' blog</a></h1>
{% 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>
@ -21,15 +16,13 @@
</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>
{% endblock content %}

View file

@ -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">
{% block head %}
{{ super() }}
<meta property="og:title" content="{{ username }}' blog" />
<meta property="og:description" content="Last 5 posts" />
<meta property="og:image" content="/static/site-image.png" />
<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>
{% 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>
{% 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>
{% endblock content %}

View file

@ -1,32 +1,23 @@
<!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="Edit '{{ title }}'" />
<meta property="og:image" content="/static/site-image.png" />
{% extends "base.html" %}
{% block head %}
{{ super() }}
<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>
<label for="token">Password</label>
</br>
<input id="token" type="password" name="token">
</div>
<meta property="og:title" content="Edit '{{ title }}'" />
{% endblock head %}
{% block content %}
<form id="submit-form" action="/api/blog/posts/edit/{{ id }}" method=POST>
<input class="token" type="text" name="token" hidden>
<label for="token">Password</label>
<br />
<input id="token" type="password" name="token">
<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>
@ -38,6 +29,4 @@
<input class="token" type="text" name="token" hidden>
<button type="submit">Delete post</button>
</form>
</body>
</html>
{% endblock content %}

View file

@ -1,34 +1,26 @@
<!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="Submit post" />
<meta property="og:image" content="/static/site-image.png" />
{% extends "base.html" %}
{% block head %}
{{ super() }}
<title>Submit post</title>
<link rel="stylesheet" href="/static/css/blog.css">
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico" />
</head>
<meta property="og:title" content="Submit post" />
{% endblock head %}
<body>
<div id="cookie-block" hidden>
<label for="token">Password</label>
<br />
<input id="token" type="password" name="token">
</div>
{% block content %}
<form id="submit-form" action="/api/blog/create" method=POST>
<input class="token" type="text" name="token" hidden>
<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>
</div>
</form>
</body>
</html>
{% endblock content %}

View file

@ -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();
}

View file

@ -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))