Add rudimentary entry page, fix main frame link navigation
This commit is contained in:
18
src/handlers/entry.rs
Normal file
18
src/handlers/entry.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use axum::extract::{State, Path};
|
||||
use axum::response::Response;
|
||||
use maud::html;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::models::entry::get_entry;
|
||||
use crate::partials::layout::Layout;
|
||||
|
||||
pub async fn get(Path(id): Path<i32>, State(pool): State<PgPool>, layout: Layout) -> Result<Response> {
|
||||
let entry = get_entry(&pool, id).await?;
|
||||
Ok(layout.render(html! {
|
||||
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
|
||||
h1 { a href=(entry.url) { (title) } }
|
||||
@let description = entry.description.unwrap_or_else(|| "No description".to_string());
|
||||
p { (description) }
|
||||
}))
|
||||
}
|
||||
@@ -13,7 +13,8 @@ pub async fn get(State(pool): State<PgPool>, layout: Layout) -> Result<Response>
|
||||
ul {
|
||||
@for entry in entries {
|
||||
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
|
||||
li { (title) }
|
||||
@let url = format!("/entry/{}", entry.id);
|
||||
li { a href=(url) { (title) } }
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod api;
|
||||
pub mod entry;
|
||||
pub mod home;
|
||||
pub mod feeds;
|
||||
|
||||
Reference in New Issue
Block a user