Add layout and feeds page, add hotwire

This commit is contained in:
2023-06-01 22:48:09 -04:00
parent 74f353b894
commit a67ffbbbed
6 changed files with 85 additions and 12 deletions

47
src/partials/layout.rs Normal file
View File

@@ -0,0 +1,47 @@
use axum::{
async_trait,
extract::FromRequestParts,
http::request::Parts,
response::{Html, IntoResponse, Response},
};
use maud::{DOCTYPE, html, Markup};
use crate::partials::header::header;
pub struct Layout;
#[async_trait]
impl<S> FromRequestParts<S> for Layout
where
S: Send + Sync,
{
type Rejection = std::convert::Infallible;
async fn from_request_parts(_parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
// extract whatever your layout needs
Ok(Self {})
}
}
impl Layout {
pub fn render(self, template: Markup) -> Response {
let with_layout = html! {
(DOCTYPE)
html lang="en" {
head {
meta charset="utf-8";
title { "crawlnicle" }
script type="module" {
r#"import * as Turbo from 'https://cdn.skypack.dev/@hotwired/turbo';"#
}
}
body {
(header())
(template)
}
}
}.into_string();
Html(with_layout).into_response()
}
}