Basic frontend rendering
parent
014c551b12
commit
e527c456b0
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,17 @@
|
||||
use rocket::{http::Status, State};
|
||||
|
||||
use crate::db::DB;
|
||||
use crate::ui::layouts::index::Index;
|
||||
use crate::util::render_bare;
|
||||
|
||||
#[get("/")]
|
||||
pub async fn site_index(db : &State<DB>) -> Result<String, (Status, String)> {
|
||||
let site = db.get_site_data().await.unwrap();
|
||||
let response = serde_json::to_string(&site).unwrap();
|
||||
|
||||
let response = render_bare(leptos::view! {
|
||||
<Index site={site}/>
|
||||
});
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
use leptos::{component, view, IntoView};
|
||||
|
||||
use crate::db::objects::Site;
|
||||
|
||||
#[component]
|
||||
pub fn Header(site: Site) -> impl IntoView {
|
||||
view!(
|
||||
<h1>{site.title}</h1>
|
||||
)
|
||||
}
|
@ -0,0 +1 @@
|
||||
pub mod header;
|
@ -0,0 +1,11 @@
|
||||
use leptos::{component, view, IntoView};
|
||||
use crate::{db::objects::Site, ui::components::header::Header};
|
||||
|
||||
#[component]
|
||||
pub fn Index(site: Site) -> impl IntoView {
|
||||
view!(
|
||||
<>
|
||||
<Header site={site}/>
|
||||
</>
|
||||
)
|
||||
}
|
@ -0,0 +1 @@
|
||||
pub mod index;
|
@ -0,0 +1,2 @@
|
||||
pub mod components;
|
||||
pub mod layouts;
|
@ -0,0 +1,10 @@
|
||||
pub fn render_bare<N>(view: N) -> String
|
||||
where N: leptos::IntoView + 'static {
|
||||
let render_result = leptos::ssr::render_to_string(|| {view});
|
||||
|
||||
let html_comment: regex::Regex = regex::Regex::new(r"<!--.*-->").unwrap();
|
||||
let leptos_string = render_result.to_string();
|
||||
let bare_string = html_comment.replace_all(&leptos_string, "");
|
||||
|
||||
bare_string.to_string()
|
||||
}
|
Loading…
Reference in New Issue