blog/backend/src/web/templates.rs

57 lines
1.2 KiB
Rust
Raw Normal View History

2023-02-11 11:48:39 +00:00
use actix_web::http;
use askama_actix::Template;
2023-02-12 08:18:56 +00:00
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
2023-02-11 11:48:39 +00:00
2023-02-12 08:18:56 +00:00
use crate::cache;
2023-02-11 11:48:39 +00:00
#[derive(Template)]
#[template(path = "status_code.html")]
pub struct StatusCode {
pub status_code: http::StatusCode,
pub message: Option<String>,
}
#[derive(Template)]
#[template(path = "web/index.html")]
pub struct Index;
#[derive(Template)]
#[template(path = "web/about.html")]
pub struct About;
2023-02-12 08:18:56 +00:00
#[derive(Serialize, Deserialize, Debug)]
pub struct PostIndexPost {
pub name: String,
pub slug: String,
pub description: String,
pub published_at: NaiveDate,
pub edited_at: Option<NaiveDate>,
pub tags: Vec<String>,
}
2023-02-11 11:48:39 +00:00
#[derive(Template)]
#[template(path = "web/posts/index.html")]
pub struct Posts {
2023-02-12 08:18:56 +00:00
pub posts: Vec<PostIndexPost>,
2023-02-11 11:48:39 +00:00
}
#[derive(Template)]
#[template(path = "web/posts/{slug}.html")]
pub struct PostBySlug {
2023-02-12 08:18:56 +00:00
// pub name: String,
// pub slug: String,
// pub published_at: NaiveDate,
// pub edited_at: Option<NaiveDate>,
// pub tags: Vec<String>,
// pub content: String,
pub post: cache::Post,
}
#[derive(Template)]
#[template(path = "web/tags/{name}.html")]
pub struct TagByName {
2023-02-11 11:48:39 +00:00
pub name: String,
2023-02-12 08:18:56 +00:00
pub posts: Vec<PostIndexPost>,
2023-02-11 11:48:39 +00:00
}