From af33bffd84ab4c30ce6eda6dec8319aabbcb768d Mon Sep 17 00:00:00 2001
From: Xe Iaso
Date: Thu, 24 Nov 2022 20:15:24 -0500
Subject: remove the rest of the ructe templates that I can remove
Signed-off-by: Xe Iaso
---
src/frontend/mastodon_share_button.tsx | 2 +-
src/handlers/blog.rs | 13 +--
src/handlers/talks.rs | 21 ++--
src/tmpl/mod.rs | 173 +++++++++++++++++++++++++++++++++
templates/blogpost.rs.html | 109 ---------------------
templates/footer.rs.html | 16 ---
templates/header.rs.html | 102 -------------------
templates/talkpost.rs.html | 124 -----------------------
8 files changed, 187 insertions(+), 373 deletions(-)
delete mode 100644 templates/blogpost.rs.html
delete mode 100644 templates/footer.rs.html
delete mode 100644 templates/header.rs.html
delete mode 100644 templates/talkpost.rs.html
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 = (
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,
Extension(state): Extension>,
headers: HeaderMap,
-) -> Result {
+) -> Result<(StatusCode, Markup)> {
let mut want: Option = 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 = 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,
Extension(state): Extension>,
headers: HeaderMap,
-) -> Result {
+) -> Result<(StatusCode, Markup)> {
let mut want: Option = 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 = 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, 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) -> 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) -> 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) -> 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))
},
)
}
diff --git a/templates/blogpost.rs.html b/templates/blogpost.rs.html
deleted file mode 100644
index 985fca0..0000000
--- a/templates/blogpost.rs.html
+++ /dev/null
@@ -1,109 +0,0 @@
-@use super::{header_html, footer_html};
-@use crate::{post::Post, tmpl::nag};
-
-@(post: Post, body: impl ToHtml, referer: Option)
-
-@:header_html(Some(&post.front_matter.title.clone()), None)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-@if post.front_matter.redirect_to.is_none() {
-
-} else {
-
-}
-
-
-
-@if let Some(to) = post.front_matter.redirect_to.clone() {
-
-
-}
-
-@Html(nag::referer(referer).0)
-
-
- @post.front_matter.title
-
- @Html(nag::prerelease(&post).0)
-
- A @post.read_time_estimate_minutes minute read.
-
- @body
-
-
-
-
-@if post.front_matter.vod.is_some() {
- This post was written live on Twitch . You can check out the stream recording on Twitch here and on YouTube here .
-}
-
-
-
-@post.front_matter.series.as_ref().unwrap_or(&"".to_string())
-@for tag in post.front_matter.tags.as_ref().unwrap_or(&Vec::new()) {#@tag }
-
-
-This article was posted on @post.detri(). Facts and circumstances may have changed since publication. Please contact me before jumping to conclusions if something seems wrong or unclear.
-
-@if post.front_matter.series.is_some() {
- Series: @post.front_matter.series.as_ref().unwrap()
-}
-
-@if post.front_matter.tags.is_some() {
- Tags: @for tag in post.front_matter.tags.as_ref().unwrap() { @tag }
-}
-
-@if post.mentions.len() != 0 {
- This post was WebMention ed at the following URLs:
-
-
-} else {
- This post was not WebMention ed yet. You could be the first!
-}
-
-The art for Mara was drawn by Selicre .
-
-The art for Cadey was drawn by ArtZora Studios .
-
-@:footer_html()
diff --git a/templates/footer.rs.html b/templates/footer.rs.html
deleted file mode 100644
index 038e6df..0000000
--- a/templates/footer.rs.html
+++ /dev/null
@@ -1,16 +0,0 @@
-@()
-
-
-
- Copyright 2012-2022 Xe Iaso (Christine Dodrill). Any and all opinions listed here are my own and not representative of my employers; future, past and present.
- Like what you see? Donate on Patreon like these awesome people !
- Looking for someone for your team? Take a look here .
- Served by @env!("out")/bin/xesite, see source code here .
- See my salary transparency data here .
-
-
-
-
-
-