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 | |
| 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>
| -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 | ||||
| -rw-r--r-- | templates/blogpost.rs.html | 109 | ||||
| -rw-r--r-- | templates/footer.rs.html | 16 | ||||
| -rw-r--r-- | templates/header.rs.html | 102 | ||||
| -rw-r--r-- | templates/talkpost.rs.html | 124 |
8 files changed, 187 insertions, 373 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)) }, ) } 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<String>) - -@:header_html(Some(&post.front_matter.title.clone()), None) - -<!-- Twitter --> -<meta name="twitter:card" content="summary" /> -<meta name="twitter:site" content="@@theprincessxena" /> -<meta name="twitter:title" content="@post.front_matter.title" /> -<meta name="twitter:description" content="Posted on @post.date.format("%Y-%m-%d")" /> - -<!-- Facebook --> -<meta property="og:type" content="website" /> -<meta property="og:title" content="@post.front_matter.title" /> -<meta property="og:site_name" content="Xe's Blog" /> - -<!-- Description --> -<meta name="description" content="@post.front_matter.title - Xe's Blog" /> -<meta name="author" content="Xe Iaso" /> - -@if post.front_matter.redirect_to.is_none() { - <link rel="canonical" href="https://xeiaso.net/@post.link" /> -} else { - <link rel="canonical" href="@post.front_matter.redirect_to.as_ref().unwrap()" /> -} - -<script type="application/ld+json"> - @{ - "@@context": "http://schema.org", - "@@type": "Article", - "headline": "@post.front_matter.title", - "image": "https://xeiaso.net/static/img/avatar.png", - "url": "https://xeiaso.net/@post.link", - "datePublished": "@post.date.format("%Y-%m-%d")", - "mainEntityOfPage": @{ - "@@type": "WebPage", - "@@id": "https://xeiaso.net/@post.link" - @}, - "author": @{ - "@@type": "Person", - "name": "Xe Iaso" - @}, - "publisher": @{ - "@@type": "Person", - "name": "Xe Iaso" - @} - @} -</script> - -@if let Some(to) = post.front_matter.redirect_to.clone() { - <meta http-equiv="refresh" content="0;URL='@to'" /> - <script> - window.location.replace("@to"); - </script> -} - -@Html(nag::referer(referer).0) - -<article> - <h1>@post.front_matter.title</h1> - - @Html(nag::prerelease(&post).0) - - <small>A @post.read_time_estimate_minutes minute read.</small> - - @body -</article> - -<hr /> - -@if post.front_matter.vod.is_some() { - <p>This post was written live on <a href="https://twitch.tv/princessxen">Twitch</a>. You can check out the stream recording on Twitch <a href="@post.front_matter.vod.as_ref().unwrap().twitch">here</a> and on YouTube <a href="@post.front_matter.vod.as_ref().unwrap().youtube">here</a>.</p> -} - -<!-- The button that should be clicked. --> -<div id="mastodon_share_button"></div> -<div id="mastodon_share_series" style="display:none">@post.front_matter.series.as_ref().unwrap_or(&"".to_string())</div> -<div id="mastodon_share_tags" style="display:none">@for tag in post.front_matter.tags.as_ref().unwrap_or(&Vec::new()) {#@tag }</div> -<script src="/static/js/mastodon_share_button.js"></script> - -<p>This article was posted on @post.detri(). Facts and circumstances may have changed since publication. Please <a href="/contact">contact me</a> before jumping to conclusions if something seems wrong or unclear.</p> - -@if post.front_matter.series.is_some() { - <p>Series: <a href="/blog/series/@post.front_matter.series.as_ref().unwrap()">@post.front_matter.series.as_ref().unwrap()</a></p> -} - -@if post.front_matter.tags.is_some() { - <p>Tags: @for tag in post.front_matter.tags.as_ref().unwrap() { <code>@tag</code> }</p> -} - -@if post.mentions.len() != 0 { - <p>This post was <a href="https://www.w3.org/TR/webmention/">WebMention</a>ed at the following URLs: - <ul> - @for mention in post.mentions { - <li><a href="@mention.source">@mention.title.unwrap_or(mention.source)</a></li> - } - </ul> - </p> -} else { - <p>This post was not <a href="https://www.w3.org/TR/webmention/">WebMention</a>ed yet. You could be the first!</p> -} - -<p>The art for Mara was drawn by <a href="https://selic.re/">Selicre</a>.</p> - -<p>The art for Cadey was drawn by <a href="https://artzorastudios.weebly.com/">ArtZora Studios</a>.</p> - -@: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 @@ -@() - </div> - <hr /> - <footer> - <blockquote>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.</blockquote> - <p>Like what you see? Donate on <a href="https://www.patreon.com/cadey">Patreon</a> like <a href="/patrons">these awesome people</a>!</p> - <p>Looking for someone for your team? Take a look <a href="/signalboost">here</a>.</p> - <p>Served by @env!("out")/bin/xesite</a>, see <a href="https://github.com/Xe/site">source code here</a>.</p> - <p>See my <a href="/salary-transparency">salary transparency data here</a>.</p> - </footer> - - </div> - - <script src="/static/js/installsw.js" defer></script> - </body> -</html> diff --git a/templates/header.rs.html b/templates/header.rs.html deleted file mode 100644 index 2a4977c..0000000 --- a/templates/header.rs.html +++ /dev/null @@ -1,102 +0,0 @@ -@use chrono::{Datelike, Utc}; -@use crate::handlers::feeds::CACHEBUSTER; - -@(title: Option<&str>, styles: Option<&str>) - -<!DOCTYPE html> -<!-- -MMMMMMMMMMMMMMMMMMNmmNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmmmd.:mmMM -MMMMMMMMMMMMMMMMMNmmmNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmmydmmmmmNMM -MMMMMMMMMMMMMMMMNm/:mNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmms /mmmmmMMM -MMMMMMMMMMMMMMMNmm:-dmMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmmmmdsdmmmmNMMM -MMMMMMMMMMMMMMMmmmmmmmNMMMMMMMMMMMNmmdhhddhhmNNMMMMMMMMMMMMMMMMNmy:hmmmmmmmmMMMM -MMMMMMMMMMMMMMNm++mmmmNMMMMMMmdyo/::.........-:/sdNMMMMMMMMMMNmmms`smmmmmmmNMMMM -MMMMMMMMMMMMMMmd.-dmmmmMMmhs/-....................-+dNMMMMMMNmmmmmmmmmmmmmmMMMMM -MMMMMMMMMMMMMNmmmmmmmmho:-...........................:sNMMNmmmmmmmmmmmmmmmNMNmdd -MMMMMMMMMMMMNmd+ydhs/-.................................-sNmmmmmmmmmmmmmmmdhyssss -MMMMMMMMMMMNNh+`........................................:dmmmmmmmmmmmmmmmyssssss -MMMMNNdhy+:-...........................................+dmmmmmmmmmmmmmmmdsssssss -MMMN+-...............................................-smmmmmmmmmmmmmmmmmysyyhdmN -MMMMNho:::-.--::-.......................----------..:hmmmmmmmmmmmmmmmmmmmNMMMMMM -MMMMMMMMNNNmmdo:......................--------------:ymmmmmmmmmmmmmmmmmmmMMMMMMM -MMMMMMMMMMds+........................-----------------+dmmmmmmmmmmmmmmmmmMMMMMMM -MMMMMMMMMh+........................--------------------:smmmmmmmmmmmmmmNMMMMMMMM -MMMMMMMNy/........................-------------::--------/hmmmmmmmmmmmNMMMMMMNmd -MMMMMMMd/........................--------------so----------odmmmmmmmmMMNmdhhysss -MMMMMMm/........................--------------+mh-----------:ymmmmdhhyysssssssss -MMMMMMo.......................---------------:dmmo------------+dmdysssssssssssss -yhdmNh:......................---------------:dmmmm+------------:sssssssssssyhhdm -sssssy.......................--------------:hmmmmmmos++:---------/sssyyhdmNMMMMM -ssssso......................--------------:hmmmNNNMNdddysso:------:yNNMMMMMMMMMM -ysssss.....................--------------/dmNyy/mMMd``d/------------sNMMMMMMMMMM -MNmdhy-...................--------------ommmh`o/NM/. smh+-----------:yNMMMMMMMMM -MMMMMN+...................------------/hmmss: `-//-.smmmmd+----------:hMMMMMMMMM -MMMMMMd:..................----------:smmmmhy+oosyysdmmy+:. `.--------/dMMMMMMMM -MMMMMMMh-................---------:smmmmmmmmmmmmmmmh/` `/s:-------sMMMMMMMM -MMMMMMMms:...............-------/ymmmmmmmmmmmmmmmd/ :dMMNy/-----+mMMMMMMM -MMMMMMmyss/..............------ommmmmmmmmmmmmmmmd. :yMMMMMMNs:---+mMMMMMMM -MMMMNdssssso-............----..odmmmmmmmmmmmmmmh:.` .sNMMMMMMMMMd/--sMMMMMMMM -MMMmysssssssh/................` -odmmmmmmmmmh+. `omMMMMMMMMMMMMh/+mMMMMMMMM -MNdyssssssymMNy-.............. `/sssso+:. `+mMMMMMMMMMMMMMMMdNMMMMMMMMM -NhssssssshNMMMMNo:............/.` `+dMMMMMMMMMMMMMMMMMMMMMMMMMMMM -ysssssssdMMMMMMMMm+-..........+ddy/.` -omMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -ssssssymMMMMMMMMMMMh/.........-oNMMNmy+--` `-+dNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -ssssydNMMMMMMMMMMMMMNy:........-hMMMMMMMNmdmMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -sssymMMMMMMMMMMMMMMMMMm+....-..:hMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -symNMMMMMMMMMMMMMMMMMMMNo.../-/dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -dNMMMMMMMMMMMMMMMMMMMMMMh:.:hyNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -la budza pu cusku lu - <<.i do snura .i ko kanro - .i do panpi .i ko gleki>> li'u ---> -<html lang="en"> - <head> - @if title.is_some() { - <title>@title.unwrap() - Xe</title> - } else { - <title>Xe</title> - } - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="/css/hack.css?bustCache=@CACHEBUSTER" /> - <link rel="stylesheet" href="/css/gruvbox-dark.css?bustCache=@CACHEBUSTER" /> - <link rel="stylesheet" href="/css/shim.css?bustCache=@CACHEBUSTER" /> - @if Utc::now().month() == 12 || Utc::now().month() == 1 || Utc::now().month() == 2 { <link rel="stylesheet" href="/css/snow.css?bustCache=@CACHEBUSTER" /> } - <link rel="manifest" href="/static/manifest.json" /> - - <link rel="alternate" title="Xe's Blog" type="application/rss+xml" href="https://xeiaso.net/blog.rss" /> - <link rel="alternate" title="Xe's Blog" type="application/json" href="https://xeiaso.net/blog.json" /> - - <link rel="apple-touch-icon" sizes="57x57" href="/static/favicon/apple-icon-57x57.png"> - <link rel="apple-touch-icon" sizes="60x60" href="/static/favicon/apple-icon-60x60.png"> - <link rel="apple-touch-icon" sizes="72x72" href="/static/favicon/apple-icon-72x72.png"> - <link rel="apple-touch-icon" sizes="76x76" href="/static/favicon/apple-icon-76x76.png"> - <link rel="apple-touch-icon" sizes="114x114" href="/static/favicon/apple-icon-114x114.png"> - <link rel="apple-touch-icon" sizes="120x120" href="/static/favicon/apple-icon-120x120.png"> - <link rel="apple-touch-icon" sizes="144x144" href="/static/favicon/apple-icon-144x144.png"> - <link rel="apple-touch-icon" sizes="152x152" href="/static/favicon/apple-icon-152x152.png"> - <link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-icon-180x180.png"> - <link rel="icon" type="image/png" sizes="192x192" href="/static/favicon/android-icon-192x192.png"> - <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon/favicon-32x32.png"> - <link rel="icon" type="image/png" sizes="96x96" href="/static/favicon/favicon-96x96.png"> - <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon/favicon-16x16.png"> - <link rel="manifest" href="/static/manifest.json"> - <meta name="msapplication-TileColor" content="#ffffff"> - <meta name="msapplication-TileImage" content="/static/favicon/ms-icon-144x144.png"> - <meta name="theme-color" content="#ffffff"> - <link href="https://mi.within.website/api/webmention/accept" rel="webmention" /> - @if styles.is_some() { - <style> - @styles.unwrap() - </style> - } - </head> - <body class="snow hack gruvbox-dark"> - <div class="container"> - <header> - <span class="logo"></span> - <nav><a href="/">Xe</a> - <a href="/blog">Blog</a> - <a href="/contact">Contact</a> - <a href="/resume">Resume</a> - <a href="/talks">Talks</a> - <a href="/signalboost">Signal Boost</a> - <a href="/feeds">Feeds</a> | <a target="_blank" rel="noopener noreferrer" href="https://graphviz.christine.website">GraphViz</a> - <a target="_blank" rel="noopener noreferrer" href="https://when-then-zen.christine.website/">When Then Zen</a></nav> - </header> - - <br /> - <br /> - <div class="snowframe"> diff --git a/templates/talkpost.rs.html b/templates/talkpost.rs.html deleted file mode 100644 index 8e30e7e..0000000 --- a/templates/talkpost.rs.html +++ /dev/null @@ -1,124 +0,0 @@ -@use super::{header_html, footer_html}; -@use crate::{post::Post, tmpl::nag}; - -@(post: Post, body: impl ToHtml, referer: Option<String>) - -@:header_html(Some(&post.front_matter.title.clone()), None) - -<!-- Twitter --> -<meta name="twitter:card" content="summary" /> -<meta name="twitter:site" content="@@theprincessxena" /> -<meta name="twitter:title" content="@post.front_matter.title" /> -<meta name="twitter:description" content="Posted on @post.date.format("%Y-%m-%d")" /> - -<!-- Facebook --> -<meta property="og:type" content="website" /> -<meta property="og:title" content="@post.front_matter.title" /> -<meta property="og:site_name" content="Xe's Blog" /> - -<!-- Description --> -<meta name="description" content="@post.front_matter.title - Xe's Blog" /> -<meta name="author" content="Xe Iaso" /> - -<link rel="canonical" href="https://xeiaso.net/@post.link" /> - -<script type="application/ld+json"> - @{ - "@@context": "http://schema.org", - "@@type": "Article", - "headline": "@post.front_matter.title", - "image": "https://xeiaso.net/static/img/avatar.png", - "url": "https://xeiaso.net/@post.link", - "datePublished": "@post.date.format("%Y-%m-%d")", - "mainEntityOfPage": @{ - "@@type": "WebPage", - "@@id": "https://xeiaso.net/@post.link" - @}, - "author": @{ - "@@type": "Person", - "name": "Xe Iaso" - @}, - "publisher": @{ - "@@type": "Person", - "name": "Xe Iaso" - @} - @} -</script> - -@Html(nag::referer(referer).0) - -@Html(nag::prerelease(&post).0) - -@body - -<a href="@post.front_matter.slides_link.as_ref().unwrap()">Link to the slides</a> - -<hr /> - -<!-- The button that should be clicked. --> -<button onclick="share_on_mastodon()">Share on Mastodon</button> - -<p>This article was posted on @post.detri(). Facts and circumstances may have changed since publication. Please <a href="/contact">contact me</a> before jumping to conclusions if something seems wrong or unclear.</p> - -@if post.front_matter.series.is_some() { - <p>Series: <a href="/blog/series/@post.front_matter.series.as_ref().unwrap()">@post.front_matter.series.as_ref().unwrap()</a></p> -} - -@if post.front_matter.tags.is_some() { - <p>Tags: @for tag in post.front_matter.tags.as_ref().unwrap() { <code>@tag</code> }</p> -} - -<script> - -// The actual function. Set this as an onclick function for your "Share on Mastodon" button -function share_on_mastodon() @{ - // Prefill the form with the user's previously-specified Mastodon instance, if applicable - var default_url = localStorage['mastodon_instance']; - - // If there is no cached instance/domain, then insert a "https://" with no domain at the start of the prompt. - if (!default_url) - default_url = "https://"; - - var instance = prompt("Enter your instance's address: (ex: https://linuxrocks.online)", default_url); - if (instance) @{ - // Handle URL formats - if ( !instance.startsWith("https://") && !instance.startsWith("http://") ) - instance = "https://" + instance; - - // get the current page's url - var url = window.location.href; - - // get the page title from the og:title meta tag, if it exists. - var title = document.querySelectorAll('meta[property="og:title"]')[0].getAttribute("content"); - - // Otherwise, use the <title> tag as the title - if (!title) var title = document.getElementsByTagName("title")[0].innerHTML; - - // Handle slash - if ( !instance.endsWith("/") ) - instance = instance + "/"; - - // Cache the instance/domain for future requests - localStorage['mastodon_instance'] = instance; - - // Hashtags - var hashtags = "#talk"; - - @if post.front_matter.tags.is_some() { - hashtags += "@for tag in post.front_matter.tags.as_ref().unwrap() { #@tag}"; - } - - // Tagging users, such as offical accounts or the author of the post - var author = "@@cadey@@pony.social"; - - // Create the Share URL - // https://someinstance.tld/share?text=URL%20encoded%20text - mastodon_url = instance + "share?text=" + encodeURIComponent(title + "\n\n" + url + "\n\n" + hashtags + " " + author); - - // Open a new window at the share location - window.open(mastodon_url, '_blank'); - @} - @} -</script> - -@:footer_html() |
