added short post description for embeds

This commit is contained in:
Leonard Lorenz 2020-11-17 20:26:14 +01:00
parent 9521674ba1
commit 1fd3bdd49f
2 changed files with 8 additions and 3 deletions

View file

@ -29,6 +29,7 @@ pub const BLOG: &str = r#"
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="{{ sitetitle }}" />
<meta property="og:description" content="{{ sitedescription }}" />
<meta property="og:image" content="/static/site-image.png" />
<title> {{ sitetitle }} </title>

View file

@ -63,11 +63,13 @@ async fn root() -> impl Responder {
#[get("/blog")]
async fn blog() -> impl Responder {
let posts = db::get_last_five_posts();
let username = config::get_from_env("USERNAME", true);
let mut context = Context::new();
context.insert("posts", &posts);
context.insert("username", &(config::get_from_env("USERNAME", true)));
context.insert("sitetitle", &(config::get_from_env("USERNAME", true) + "' blog"));
context.insert("username", &username);
context.insert("sitetitle", &format!("{}' blog'", &username));
context.insert("sitedescription", &format!("Last 5 posts of {}' blog'", &username));
// one-off render blog template with context
let result = Tera::one_off(
@ -85,11 +87,13 @@ async fn blog_by_id(web::Path(post_id): web::Path<std::string::String>) -> impl
let (valid, id) = id_valid(post_id);
if valid {
let post = db::get_post_by_id(id as i32);
let username = config::get_from_env("USERNAME", true);
let mut context = Context::new();
context.insert("posts", &[&post]);
context.insert("username", &(config::get_from_env("USERNAME", true)));
context.insert("username", &username);
context.insert("sitetitle", &post.title);
context.insert("sitedescription", &format!("Last 5 posts of {}' blog'", &username));
// one-off render blog template with context
let result = Tera::one_off(