renders to html string
parent
95ce2d4668
commit
ef3bddbee4
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,62 @@
|
||||
use chrono::DateTime;
|
||||
use futures::executor;
|
||||
use yew::{function_component, html, Html, ServerRenderer};
|
||||
|
||||
use crate::{
|
||||
data::{Outbox, Person},
|
||||
error::Ærror,
|
||||
};
|
||||
|
||||
#[derive(yew::Properties, PartialEq)]
|
||||
struct Props {
|
||||
pub outbox: Outbox,
|
||||
pub author: Person,
|
||||
pub archive_time: DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
outbox: Outbox,
|
||||
author: Person,
|
||||
archive_time: DateTime<chrono::Utc>,
|
||||
) -> Result<String, Ærror> {
|
||||
let output_string = executor::block_on(render_async(outbox, author, archive_time));
|
||||
|
||||
Ok(output_string)
|
||||
}
|
||||
|
||||
async fn render_async(
|
||||
outbox: Outbox,
|
||||
author: Person,
|
||||
archive_time: DateTime<chrono::Utc>,
|
||||
) -> String {
|
||||
let renderer = ServerRenderer::<Layout>::with_props(move || -> Props {
|
||||
Props {
|
||||
outbox,
|
||||
author,
|
||||
archive_time,
|
||||
}
|
||||
})
|
||||
.hydratable(false);
|
||||
|
||||
renderer.render().await
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
fn Layout(props: &Props) -> Html {
|
||||
html! {
|
||||
<>
|
||||
<ProfileHeader outbox={props.outbox.clone()} author={props.author.clone()} archive_time={props.archive_time}/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
fn ProfileHeader(props: &Props) -> Html {
|
||||
html! {
|
||||
<p>
|
||||
{"Generated on "}
|
||||
{props.archive_time.to_rfc2822()}
|
||||
</p>
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue