refactor(templates): Move thread page template to Askama
This commit is contained in:
parent
94d5e02bb3
commit
69583b1236
4 changed files with 17 additions and 21 deletions
|
@ -142,7 +142,6 @@ fn start_renderer() -> Addr<Syn, Renderer> {
|
||||||
tera.add_raw_templates(vec![
|
tera.add_raw_templates(vec![
|
||||||
("post.html", include_str!("../templates/post.html")),
|
("post.html", include_str!("../templates/post.html")),
|
||||||
("search.html", include_str!("../templates/search.html")),
|
("search.html", include_str!("../templates/search.html")),
|
||||||
("thread.html", include_str!("../templates/thread.html")),
|
|
||||||
]).expect("Could not compile templates");
|
]).expect("Could not compile templates");
|
||||||
|
|
||||||
let comrak = comrak::ComrakOptions{
|
let comrak = comrak::ComrakOptions{
|
||||||
|
|
|
@ -108,7 +108,7 @@ message!(ThreadPage, Result<String>);
|
||||||
struct RenderablePost {
|
struct RenderablePost {
|
||||||
id: i32,
|
id: i32,
|
||||||
body: String,
|
body: String,
|
||||||
posted: String, // FormattedDate,
|
posted: FormattedDate,
|
||||||
author_name: String,
|
author_name: String,
|
||||||
author_gravatar: String,
|
author_gravatar: String,
|
||||||
editable: bool,
|
editable: bool,
|
||||||
|
@ -116,7 +116,8 @@ struct RenderablePost {
|
||||||
|
|
||||||
/// This structure represents the transformed thread data with
|
/// This structure represents the transformed thread data with
|
||||||
/// Markdown rendering and other changes applied.
|
/// Markdown rendering and other changes applied.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Template)]
|
||||||
|
#[template(path = "thread.html")]
|
||||||
struct RenderableThreadPage {
|
struct RenderableThreadPage {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: String,
|
title: String,
|
||||||
|
@ -137,7 +138,7 @@ fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadP
|
||||||
RenderablePost {
|
RenderablePost {
|
||||||
id: post.id,
|
id: post.id,
|
||||||
body: markdown_to_html(&post.body, comrak),
|
body: markdown_to_html(&post.body, comrak),
|
||||||
posted: format!("{}", FormattedDate(post.posted)), // post.posted.into(),
|
posted: FormattedDate(post.posted),
|
||||||
author_name: post.author_name.clone(),
|
author_name: post.author_name.clone(),
|
||||||
author_gravatar: md5_hex(post.author_email.as_bytes()),
|
author_gravatar: md5_hex(post.author_email.as_bytes()),
|
||||||
editable,
|
editable,
|
||||||
|
@ -147,7 +148,7 @@ fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadP
|
||||||
RenderableThreadPage {
|
RenderableThreadPage {
|
||||||
posts,
|
posts,
|
||||||
id: page.thread.id,
|
id: page.thread.id,
|
||||||
title: escape_html(&page.thread.title),
|
title: page.thread.title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +157,7 @@ impl Handler<ThreadPage> for Renderer {
|
||||||
|
|
||||||
fn handle(&mut self, msg: ThreadPage, _: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, msg: ThreadPage, _: &mut Self::Context) -> Self::Result {
|
||||||
let renderable = prepare_thread(&self.comrak, msg);
|
let renderable = prepare_thread(&self.comrak, msg);
|
||||||
Ok(self.tera.render("thread.html", &renderable)?)
|
renderable.render().map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<form method="get" action="/search">
|
<form method="get" action="/search">
|
||||||
<input class="mdl-textfield__input" type="search" id="search-query" aria-label="Search" name="query">
|
<input class="mdl-textfield__input" type="search" id="search-query" aria-label="Search" name="query">
|
||||||
<label class="mdl-textfield__label mdl-color-text--blue-grey-100" for="search-query">Search query...</label>
|
<label class="mdl-textfield__label mdl-color-text--blue-grey-100" for="search-query">Search query...</label>
|
||||||
<input type="submit" hidden /> <!-- TODO: necessary? -->
|
<input type="submit" hidden />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
||||||
<title>Converse: {{ title | safe }}</title>
|
<title>Converse: {{ title }}</title>
|
||||||
|
|
||||||
<!-- TODO -->
|
<!-- TODO -->
|
||||||
<meta http-equiv="Content-Security-Policy" content="script-src https://code.getmdl.io 'self';">
|
<meta http-equiv="Content-Security-Policy" content="script-src https://code.getmdl.io 'self';">
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<div class="mdl-layout mdl-layout--fixed-header mdl-js-layout mdl-color--grey-100">
|
<div class="mdl-layout mdl-layout--fixed-header mdl-js-layout mdl-color--grey-100">
|
||||||
<header class="mdl-layout__header mdl-color--primary-dark">
|
<header class="mdl-layout__header mdl-color--primary-dark">
|
||||||
<div class="mdl-layout__header-row">
|
<div class="mdl-layout__header-row">
|
||||||
<a href="/" class="mdl-layout-title mdl-color-text--blue-grey-50 cvs-title">Converse: {{ title | safe }}</a>
|
<a href="/" class="mdl-layout-title mdl-color-text--blue-grey-50 cvs-title">Converse: {{ title }}</a>
|
||||||
<div class="mdl-layout-spacer"></div>
|
<div class="mdl-layout-spacer"></div>
|
||||||
<a href="/">
|
<a href="/">
|
||||||
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent mdl-js-ripple-effect">
|
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent mdl-js-ripple-effect">
|
||||||
|
@ -35,35 +35,31 @@
|
||||||
<main class="mdl-layout__content">
|
<main class="mdl-layout__content">
|
||||||
{% for post in posts -%}
|
{% for post in posts -%}
|
||||||
<section id="post-{{ post.id }}" class="section--center mdl-grid mdl-grid--no-spacing">
|
<section id="post-{{ post.id }}" class="section--center mdl-grid mdl-grid--no-spacing">
|
||||||
{# card to display avatars on desktop #}
|
<!-- card to display avatars on desktop -->
|
||||||
<div class="mdl-card mdl-shadow--2dp mdl-cell--2-col mdl-cell--hide-phone mdl-cell--hide-tablet avatar-box">
|
<div class="mdl-card mdl-shadow--2dp mdl-cell--2-col mdl-cell--hide-phone mdl-cell--hide-tablet avatar-box">
|
||||||
<div class="avatar-card">
|
<div class="avatar-card">
|
||||||
<img class="desktop-avatar" src="https://www.gravatar.com/avatar/{{ post.author_gravatar }}?d=monsterid&s=160" />
|
<img class="desktop-avatar" src="https://www.gravatar.com/avatar/{{ post.author_gravatar }}?d=monsterid&s=160" />
|
||||||
<p class="user-name">{{ post.author_name }}</p>
|
<p class="user-name">{{ post.author_name }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{# card for main post content #}
|
<!-- card for main post content -->
|
||||||
<div class="mdl-card mdl-shadow--2dp post-box mdl-cell--10-col">
|
<div class="mdl-card mdl-shadow--2dp post-box mdl-cell--10-col">
|
||||||
{# card section for displaying user & post information on mobile #}
|
<!-- card section for displaying user & post information on mobile -->
|
||||||
<div class="mdl-card__supporting-text mdl-card--border mdl-cell--hide-desktop mdl-color-text--blue-grey-500 mobile-user">
|
<div class="mdl-card__supporting-text mdl-card--border mdl-cell--hide-desktop mdl-color-text--blue-grey-500 mobile-user">
|
||||||
<img class="mobile-avatar" src="https://www.gravatar.com/avatar/{{ post.author_gravatar }}?d=monsterid"/>
|
<img class="mobile-avatar" src="https://www.gravatar.com/avatar/{{ post.author_gravatar }}?d=monsterid"/>
|
||||||
<span> {{ post.author_name }} posted on </span>
|
<span> {{ post.author_name }} posted on </span>
|
||||||
<a class="mdl-color-text--blue-grey-500 mobile-date" href="/thread/{{ id }}#post-{{ post.id }}">{{ post.posted }}</a>
|
<a class="mdl-color-text--blue-grey-500 mobile-date" href="/thread/{{ id }}#post-{{ post.id }}">{{ post.posted }}</a>
|
||||||
</div>
|
</div>
|
||||||
{# card section to display post date on desktop #}
|
<!-- card section to display post date on desktop -->
|
||||||
<div class="mdl-card__menu mdl-cell--hide-phone mdl-cell--hide-tablet">
|
<div class="mdl-card__menu mdl-cell--hide-phone mdl-cell--hide-tablet">
|
||||||
<a class="post-date mdl-color-text--blue-grey-500" href="/thread/{{ id }}#post-{{ post.id }}">{{ post.posted }}</a>
|
<a class="post-date mdl-color-text--blue-grey-500" href="/thread/{{ id }}#post-{{ post.id }}">{{ post.posted }}</a>
|
||||||
</div>
|
</div>
|
||||||
{# card section for actual post content #}
|
<!-- card section for actual post content -->
|
||||||
<div class="mdl-card__supporting-text post-box">{{ post.body|safe }}</div>
|
<div class="mdl-card__supporting-text post-box">{{ post.body|safe }}</div>
|
||||||
{# card section for post actions #}
|
<!-- card section for post actions -->
|
||||||
<div class="mdl-card__actions post-actions">
|
<div class="mdl-card__actions post-actions">
|
||||||
<div class="mdl-layout-spacer"></div>
|
<div class="mdl-layout-spacer"></div>
|
||||||
|
|
||||||
{#%- TODO if post.editable %#}
|
|
||||||
<!-- <a href="/post/{{ post.id }}/edit" class="badge badge-light border m-1 p-1">Edit</a> -->
|
|
||||||
{#% endif -%#}
|
|
||||||
|
|
||||||
{% if post.editable %}
|
{% if post.editable %}
|
||||||
<a href="/post/{{ post.id }}/edit" class="mdl-button mdl-js-button mdl-button--accent" id="edit-post-{{ post.id }}" aria-label="Edit post">
|
<a href="/post/{{ post.id }}/edit" class="mdl-button mdl-js-button mdl-button--accent" id="edit-post-{{ post.id }}" aria-label="Edit post">
|
||||||
<i class="material-icons">edit</i>
|
<i class="material-icons">edit</i>
|
||||||
|
@ -79,7 +75,7 @@
|
||||||
</section>
|
</section>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{# section for writing a response on the same page #}
|
<!-- section for writing a response on the same page -->
|
||||||
<section id="post-reply" class="section--center mdl-grid mdl-grid--no-spacing reply-box">
|
<section id="post-reply" class="section--center mdl-grid mdl-grid--no-spacing reply-box">
|
||||||
<div class="mdl-card mdl-shadow--2dp mdl-cell--12-col">
|
<div class="mdl-card mdl-shadow--2dp mdl-cell--12-col">
|
||||||
<form id="reply-form" action="/thread/reply" method="post">
|
<form id="reply-form" action="/thread/reply" method="post">
|
||||||
|
|
Loading…
Reference in a new issue