diff options
| author | Xe Iaso <me@christine.website> | 2022-11-24 20:15:24 -0500 |
|---|---|---|
| committer | Xe Iaso <me@christine.website> | 2022-11-24 20:15:24 -0500 |
| commit | af33bffd84ab4c30ce6eda6dec8319aabbcb768d (patch) | |
| tree | 966b3f0e75fe07f4e736e6a942fa00b67d249dd1 /src | |
| parent | e174b7ba4dc1f6e755d6142f0d26a3e6357be771 (diff) | |
| download | xesite-af33bffd84ab4c30ce6eda6dec8319aabbcb768d.tar.xz xesite-af33bffd84ab4c30ce6eda6dec8319aabbcb768d.zip | |
remove the rest of the ructe templates that I can remove
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'src')
| -rw-r--r-- | src/frontend/mastodon_share_button.tsx | 2 | ||||
| -rw-r--r-- | src/handlers/blog.rs | 13 | ||||
| -rw-r--r-- | src/handlers/talks.rs | 21 | ||||
| -rw-r--r-- | src/tmpl/mod.rs | 173 |
4 files changed, 187 insertions, 22 deletions
diff --git a/src/frontend/mastodon_share_button.tsx b/src/frontend/mastodon_share_button.tsx index 64164a7..d689abd 100644 --- a/src/frontend/mastodon_share_button.tsx +++ b/src/frontend/mastodon_share_button.tsx @@ -18,7 +18,7 @@ r(() => { ${articleURL} -${series}${tags.innerText}@cadey@pony.social`; +${series}${tags.innerText} @cadey@pony.social`; const instanceBox = ( <input type="text" placeholder="https://pony.social" value={defaultURL} /> diff --git a/src/handlers/blog.rs b/src/handlers/blog.rs index 09cef8b..fda6c7f 100644 --- a/src/handlers/blog.rs +++ b/src/handlers/blog.rs @@ -1,9 +1,8 @@ use super::Result; -use crate::{app::State, post::Post, templates, tmpl}; +use crate::{app::State, post::Post, tmpl}; use axum::{ extract::{Extension, Path}, http::StatusCode, - response::Html, }; use http::HeaderMap; use lazy_static::lazy_static; @@ -79,7 +78,7 @@ pub async fn post_view( Path(name): Path<String>, Extension(state): Extension<Arc<State>>, headers: HeaderMap, -) -> Result { +) -> Result<(StatusCode, Markup)> { let mut want: Option<Post> = None; let want_link = format!("blog/{}", name); @@ -97,15 +96,13 @@ pub async fn post_view( }; match want { - None => Err(super::Error::PostNotFound(name)), + None => Ok((StatusCode::NOT_FOUND, tmpl::not_found(want_link))), Some(post) => { HIT_COUNTER .with_label_values(&[name.clone().as_str()]) .inc(); - let body = templates::Html(post.body_html.clone()); - let mut result: Vec<u8> = vec![]; - templates::blogpost_html(&mut result, post, body, referer)?; - Ok(Html(result)) + let body = maud::PreEscaped(&post.body_html); + Ok((StatusCode::OK, tmpl::blog_view(&post, body, referer))) } } } diff --git a/src/handlers/talks.rs b/src/handlers/talks.rs index 1b27a16..ad37517 100644 --- a/src/handlers/talks.rs +++ b/src/handlers/talks.rs @@ -1,10 +1,7 @@ -use super::{Error::*, Result}; -use crate::{app::State, post::Post, templates, tmpl}; -use axum::{ - extract::{Extension, Path}, - response::Html, -}; -use http::header::HeaderMap; +use super::Result; +use crate::{app::State, post::Post, tmpl}; +use axum::extract::{Extension, Path}; +use http::{header::HeaderMap, StatusCode}; use lazy_static::lazy_static; use maud::Markup; use prometheus::{opts, register_int_counter_vec, IntCounterVec}; @@ -30,7 +27,7 @@ pub async fn post_view( Path(name): Path<String>, Extension(state): Extension<Arc<State>>, headers: HeaderMap, -) -> Result { +) -> Result<(StatusCode, Markup)> { let mut want: Option<Post> = None; let want_link = format!("talks/{}", name); @@ -48,15 +45,13 @@ pub async fn post_view( }; match want { - None => Err(PostNotFound(name).into()), + None => Ok((StatusCode::NOT_FOUND, tmpl::not_found(want_link))), Some(post) => { HIT_COUNTER .with_label_values(&[name.clone().as_str()]) .inc(); - let body = templates::Html(post.body_html.clone()); - let mut result: Vec<u8> = vec![]; - templates::talkpost_html(&mut result, post, body, referer)?; - Ok(Html(result)) + let body = maud::PreEscaped(&post.body_html); + Ok((StatusCode::OK, tmpl::talk_view(&post, body, referer))) } } } diff --git a/src/tmpl/mod.rs b/src/tmpl/mod.rs index 9535be2..707bf6e 100644 --- a/src/tmpl/mod.rs +++ b/src/tmpl/mod.rs @@ -166,6 +166,176 @@ pub fn post_index(posts: &Vec<Post>, title: &str, show_extra: bool) -> Markup { ) } +fn post_metadata(post: &Post) -> Markup { + html! { + meta name="twitter:card" content="summary"; + meta name="twitter:site" content="@theprincessxena"; + meta name="twitter:title" content={(post.front_matter.title)}; + meta property="og:type" content="website"; + meta property="og:title" content={(post.front_matter.title)}; + meta property="og:site_name" content="Xe's Blog"; + meta name="description" content={(post.front_matter.title) " - Xe's Blog"}; + meta name="author" content="Xe Iaso"; + + @if let Some(redirect_to) = &post.front_matter.redirect_to { + link rel="canonical" href=(redirect_to); + meta http-equiv="refresh" content=(format!("0;URL='{redirect_to}'")); + } @else { + link rel="canonical" href={"https://xeiaso.net/" (post.link)}; + } + } +} + +fn share_button(post: &Post) -> Markup { + html! { + div # mastodon_share_button {} + div # mastodon_share_series style="display:none" {(post.front_matter.series.as_ref().unwrap_or(&"".to_string()))} + div # mastodon_share_tags style="display:none" {@for tag in post.front_matter.tags.as_ref().unwrap_or(&Vec::new()) {"#" (tag) " "}} + script r#type="module" src="/static/js/mastodon_share_button.js" {} + } +} + +fn twitch_vod(post: &Post) -> Markup { + html! { + @if let Some(vod) = &post.front_matter.vod { + p { + "This post was written live on " + a href="https://twitch.tv/princessxen" {"Twitch"} + ". You can check out the stream recording on " + a href=(vod.twitch) {"Twitch"} + " and on " + a href=(vod.youtube) {"YouTube"} + ". If you are reading this in the first day or so of this post being published, you will need to watch it on Twitch." + } + } + } +} + +pub fn blog_view(post: &Post, body: PreEscaped<&String>, referer: Option<String>) -> Markup { + base( + Some(&post.front_matter.title), + None, + html! { + (post_metadata(post)) + (nag::referer(referer)) + + article { + h1 {(post.front_matter.title)} + + (nag::prerelease(post)) + + small { + "Read time in minutes: " + (post.read_time_estimate_minutes) + } + + (body) + } + + (share_button(post)) + (twitch_vod(post)) + + p { + "This article was posted on " + (post.detri()) + ". Facts and circumstances may have changed since publication Please " + a href="/contact" {"contact me"} + " before jumping to conclusions if something seems wrong or unclear." + } + + @if let Some(series) = &post.front_matter.series { + p { + "Series: " + a href={"/blog/series/" (series)} {(series)} + } + } + + @if let Some(tags) = &post.front_matter.tags { + p { + "Tags: " + @for tag in tags { + code {(tag)} + " " + } + } + } + + @if post.mentions.is_empty() { + p { + "This post was not " + a href="https://www.w3.org/TR/webmention/" {"WebMention"} + "ed yet. You could be the first!" + } + } @else { + ul { + @for mention in &post.mentions { + li { + a href=(mention.source) {(mention.title.as_ref().unwrap_or(&mention.source))} + } + } + } + } + + p { + "The art for Mara was drawn by " + a href="https://selic.re/" {"Selicre"} + "." + } + + p { + "The art for Cadey was drawn by " + a href="https://artzorastudios.weebly.com/" {"ArtZorea Studios"} + "." + } + }, + ) +} + +pub fn talk_view(post: &Post, body: PreEscaped<&String>, referer: Option<String>) -> Markup { + base( + Some(&post.front_matter.title), + None, + html! { + (post_metadata(post)) + (nag::referer(referer)) + + article { + {(post.front_matter.title)} + + (nag::prerelease(post)) + + (body) + } + + @if let Some(slides) = &post.front_matter.slides_link { + a href=(slides) {"Link to the slides"} + } + + (share_button(post)) + + p { + "This talk was posted on " + (post.detri()) + ". Facts and circumstances may have changed since publication Please " + a href="/contact" {"contact me"} + " before jumping to conclusions if something seems wrong or unclear." + } + + p { + "The art for Mara was drawn by " + a href="https://selic.re/" {"Selicre"} + "." + } + + p { + "The art for Cadey was drawn by " + a href="https://artzorastudios.weebly.com/" {"ArtZorea Studios"} + "." + } + }, + ) +} + pub fn gallery_index(posts: &Vec<Post>) -> Markup { base( Some("Gallery"), @@ -205,6 +375,7 @@ pub fn gallery_post(post: &Post) -> Markup { Some(&post.front_matter.title), None, html! { + (post_metadata(post)) h1 {(post.front_matter.title)} (PreEscaped(&post.body_html)) @@ -230,6 +401,8 @@ pub fn gallery_post(post: &Post) -> Markup { } } } + + (share_button(post)) }, ) } |
