aboutsummaryrefslogtreecommitdiff
path: root/lib/xesite_markdown
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-10-30 18:24:09 -0400
committerXe Iaso <me@christine.website>2022-10-30 18:24:09 -0400
commit23c64aebf57b3a9f9db4c08af001f01af25d732d (patch)
tree6a3e6aafe2eef06aaea2faa5b8c7711be328c86e /lib/xesite_markdown
parent5d2935617a0e4bf615a8ffc0f7c1f96d9479cbd8 (diff)
downloadxesite-23c64aebf57b3a9f9db4c08af001f01af25d732d.tar.xz
xesite-23c64aebf57b3a9f9db4c08af001f01af25d732d.zip
various site updates
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'lib/xesite_markdown')
-rw-r--r--lib/xesite_markdown/Cargo.toml6
-rw-r--r--lib/xesite_markdown/src/lib.rs38
2 files changed, 43 insertions, 1 deletions
diff --git a/lib/xesite_markdown/Cargo.toml b/lib/xesite_markdown/Cargo.toml
index 62eb817..08e196f 100644
--- a/lib/xesite_markdown/Cargo.toml
+++ b/lib/xesite_markdown/Cargo.toml
@@ -8,12 +8,16 @@ edition = "2021"
[dependencies]
color-eyre = "0.6"
comrak = "0.14.0"
+hex = "0.4"
lazy_static = "1.4"
lol_html = "0.3"
maud = "0.23.0"
+sha2 = "0.10"
+serde_json = "1"
thiserror = "1"
tracing = "0.1"
url = "2"
# local deps
-xesite_templates = { path = "../xesite_templates" } \ No newline at end of file
+xesite_templates = { path = "../xesite_templates" }
+xesite_types = { path = "../xesite_types" } \ No newline at end of file
diff --git a/lib/xesite_markdown/src/lib.rs b/lib/xesite_markdown/src/lib.rs
index fad2b3a..5bd6dfa 100644
--- a/lib/xesite_markdown/src/lib.rs
+++ b/lib/xesite_markdown/src/lib.rs
@@ -8,8 +8,16 @@ use comrak::{
use lazy_static::lazy_static;
use lol_html::{element, html_content::ContentType, rewrite_str, RewriteStrSettings};
use maud::PreEscaped;
+use sha2::{Digest, Sha256};
use std::{cell::RefCell, io::Write};
use url::Url;
+use xesite_types::mastodon::{Toot, User};
+
+pub fn hash_string(inp: String) -> String {
+ let mut h = Sha256::new();
+ h.update(&inp.as_bytes());
+ hex::encode(h.finalize())
+}
lazy_static! {
static ref SYNTECT_ADAPTER: SyntectAdapter<'static> = SyntectAdapter::new("base16-mocha.dark");
@@ -175,6 +183,36 @@ pub fn render(inp: &str) -> Result<String> {
el.replace(&xesite_templates::video(path).0, ContentType::Html);
Ok(())
}),
+ #[cfg(not(target_arch = "wasm32"))]
+ element!("xeblog-toot", |el| {
+ use serde_json::from_reader;
+ use std::fs;
+
+ let mut toot_url = el
+ .get_attribute("url")
+ .ok_or(Error::MissingElementAttribute("url".to_string()))?;
+
+ if !toot_url.ends_with(".json") {
+ toot_url = format!("{toot_url}.json");
+ }
+
+ let toot_fname = format!("./data/toots/{}.json", hash_string(toot_url));
+ tracing::debug!("opening {toot_fname}");
+ let mut fin = fs::File::open(&toot_fname)?;
+ let t: Toot = from_reader(&mut fin)?;
+
+ let user_fname = format!(
+ "./data/users/{}.json",
+ hash_string(format!("{}.json", t.attributed_to.clone()))
+ );
+ tracing::debug!("opening {user_fname}");
+ let mut fin = fs::File::open(&user_fname)?;
+
+ let u: User = from_reader(&mut fin)?;
+
+ el.replace(&xesite_templates::toot_embed(u, t).0, ContentType::Html);
+ Ok(())
+ }),
],
..RewriteStrSettings::default()
},