implement post page rendering
This commit is contained in:
parent
1110a2614b
commit
bbcb48beeb
|
@ -148,7 +148,7 @@ async fn default_route(_req: Request, url: Url) -> MyResult<Response> {
|
||||||
} else {
|
} else {
|
||||||
// TODO: Actually render the page...
|
// TODO: Actually render the page...
|
||||||
return Response::new_with_opt_str_and_init(
|
return Response::new_with_opt_str_and_init(
|
||||||
Some(&blog::PostContentCache::find_or_render(&post).await.content),
|
Some(&render::render_post(post).await?),
|
||||||
ResponseInit::new()
|
ResponseInit::new()
|
||||||
.status(200)
|
.status(200)
|
||||||
.headers(headers!{
|
.headers(headers!{
|
||||||
|
|
|
@ -60,6 +60,15 @@ struct HomePageContext {
|
||||||
next: Option<String>
|
next: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct PostContext {
|
||||||
|
blog: &'static BlogRootContext,
|
||||||
|
title: String,
|
||||||
|
url: String,
|
||||||
|
timestamp: u64,
|
||||||
|
content: String
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref THEME_CONFIG: serde_json::Value = serde_json::from_str(
|
static ref THEME_CONFIG: serde_json::Value = serde_json::from_str(
|
||||||
include_str!("../theme_config.json")).unwrap();
|
include_str!("../theme_config.json")).unwrap();
|
||||||
|
@ -157,3 +166,18 @@ pub async fn render_homepage(url: Url) -> MyResult<String> {
|
||||||
hbs.render("home.hbs", &context)
|
hbs.render("home.hbs", &context)
|
||||||
.map_err(|e| Error::BadRequest(format!("{:#?}", e)))
|
.map_err(|e| Error::BadRequest(format!("{:#?}", e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn render_post(post: blog::Post) -> MyResult<String> {
|
||||||
|
let hbs = build_handlebars();
|
||||||
|
let post_cache = blog::PostContentCache::find_or_render(&post).await;
|
||||||
|
let context = PostContext {
|
||||||
|
blog: &ROOT_CONTEXT,
|
||||||
|
title: post.title,
|
||||||
|
url: post.url,
|
||||||
|
timestamp: post.timestamp,
|
||||||
|
content: post_cache.content
|
||||||
|
};
|
||||||
|
|
||||||
|
hbs.render("post.hbs", &context)
|
||||||
|
.map_err(|e| Error::BadRequest(format!("{:#?}", e)))
|
||||||
|
}
|
24
theme/default/post.hbs
Normal file
24
theme/default/post.hbs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<html lang="{{ blog.lang }}">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{ title }} - {{ blog.title }}</title>
|
||||||
|
<link rel="stylesheet" href="/static/style.css?ver={{ build_num 0 }}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="page-wrapper">
|
||||||
|
{{> sidebar.hbs }}
|
||||||
|
<article class="content">
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
<span class="date">{{ format_date timestamp "%e %b, %Y" }}</span>
|
||||||
|
{{{ content }}}
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<div class="toc-wrapper hidden">
|
||||||
|
<div class="toc">
|
||||||
|
<!-- This will be generated dynamically by JavaScript -->
|
||||||
|
<!-- We don't handle this in backend -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="/static/script.js?ver={{ build_num 0 }}"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue