WIP: Blogs
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-14 11:30:58 +02:00
parent 4b5fa8561c
commit cef6e9f4b1
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 33 additions and 0 deletions

View file

@ -27,6 +27,9 @@ mod portfolio;
#[path = "routes/contrib.rs"] #[path = "routes/contrib.rs"]
mod contrib; mod contrib;
#[path = "routes/blog.rs"]
mod blog;
#[actix_web::main] #[actix_web::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let config = config::get_config("./config/config.toml"); let config = config::get_config("./config/config.toml");
@ -55,6 +58,8 @@ async fn main() -> Result<()> {
.service(networks::page) .service(networks::page)
.service(portfolio::page) .service(portfolio::page)
.service(contrib::page) .service(contrib::page)
.service(blog::index)
.service(blog::page)
.service(Files::new("/", config.static_location.clone())) .service(Files::new("/", config.static_location.clone()))
.default_service(web::to(not_found::page)) .default_service(web::to(not_found::page))
}) })

28
src/routes/blog.rs Normal file
View file

@ -0,0 +1,28 @@
use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content;
use crate::config::Config;
#[get("/blog")]
pub async fn index(config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(get_index(config.get_ref().clone()))
}
#[derive(Content)]
struct BlogIndexTemplate {}
#[once(time = 60)]
pub fn get_index(_config: Config) -> String {
String::from("Salut pour tous")
}
#[get("/blog/{id}")]
pub async fn page(path: web::Path<(u32,)>, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(get_page(path.into_inner().0, config.get_ref().clone()))
}
#[once(time = 60)]
pub fn get_page(id: u32, _config: Config) -> String {
format!("Salut pour {id}")
}