Add rudimentary entry page, fix main frame link navigation
This commit is contained in:
parent
0b7acadd60
commit
ea236dff4e
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;
|
||||
|
@ -42,6 +42,7 @@ async fn main() -> Result<()> {
|
||||
.route("/api/v1/entry/:id", get(handlers::api::entry::get))
|
||||
.route("/", get(handlers::home::get))
|
||||
.route("/feeds", get(handlers::feeds::get))
|
||||
.route("/entry/:id", get(handlers::entry::get))
|
||||
.with_state(AppState {
|
||||
pool,
|
||||
config,
|
||||
|
@ -45,7 +45,7 @@ impl Layout {
|
||||
}
|
||||
body {
|
||||
(header())
|
||||
turbo-frame id="main" {
|
||||
turbo-frame id="main" data-turbo-action="advance" {
|
||||
(template)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user