aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-10-30 14:22:56 -0400
committerXe Iaso <me@christine.website>2022-10-30 14:22:56 -0400
commitc654d84537a50e164c57852fc89216eec8e55d69 (patch)
tree7844201ca37fe998309f81b000dc86477d05e4ca /lib
parent79a0a167ee87e925091a55f7de88d02bcea42c92 (diff)
downloadxesite-c654d84537a50e164c57852fc89216eec8e55d69.tar.xz
xesite-c654d84537a50e164c57852fc89216eec8e55d69.zip
start working on a mastodon post embed tag
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'lib')
-rw-r--r--lib/xesite_templates/Cargo.toml4
-rw-r--r--lib/xesite_templates/src/lib.rs35
-rw-r--r--lib/xesite_types/Cargo.toml1
-rw-r--r--lib/xesite_types/src/mastodon.rs118
4 files changed, 101 insertions, 57 deletions
diff --git a/lib/xesite_templates/Cargo.toml b/lib/xesite_templates/Cargo.toml
index 06ab92d..3d66e59 100644
--- a/lib/xesite_templates/Cargo.toml
+++ b/lib/xesite_templates/Cargo.toml
@@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-maud = "0.23.0" \ No newline at end of file
+maud = "0.23.0"
+
+xesite_types = { path = "../xesite_types" } \ No newline at end of file
diff --git a/lib/xesite_templates/src/lib.rs b/lib/xesite_templates/src/lib.rs
index a24e239..b3298d9 100644
--- a/lib/xesite_templates/src/lib.rs
+++ b/lib/xesite_templates/src/lib.rs
@@ -1,4 +1,5 @@
use maud::{html, Markup, PreEscaped};
+use xesite_types::mastodon::{Toot, User};
pub fn talk_warning() -> Markup {
html! {
@@ -165,3 +166,37 @@ pub fn advertiser_nag() -> Markup {
}
}
}
+
+pub fn toot_embed(u: User, t: Toot) -> Markup {
+ html! {
+ .media {
+ .media-left {
+ .avatarholder {
+ img src=(u.icon.url);
+ }
+ }
+ .media-body {
+ .media-heading { (u.name) " @" (u.preferred_username) }
+ .media-content {
+ (PreEscaped::<String>(t.content))
+
+ @for att in &t.attachment {
+ @if att.media_type.starts_with("image/") {
+ img src=(att.url) alt=(att.name.clone().unwrap_or("no description provided".into()));
+ }
+
+ @if att.media_type.starts_with("video/") {
+ video width=(att.width) height=(att.height) controls {
+ source src=(att.url) type=(att.media_type);
+ "Your browser does not support the video tag, see this URL: "
+ a href=(att.url) {(att.url)}
+ }
+ }
+ }
+
+ a href=(t.url) { "Link" }
+ }
+ }
+ }
+ }
+}
diff --git a/lib/xesite_types/Cargo.toml b/lib/xesite_types/Cargo.toml
index 6d1854d..60f6bbf 100644
--- a/lib/xesite_types/Cargo.toml
+++ b/lib/xesite_types/Cargo.toml
@@ -9,5 +9,6 @@ license = "zlib"
[dependencies]
chrono = { version = "0.4", features = [ "serde" ] }
+html2text = "0.4"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1" \ No newline at end of file
diff --git a/lib/xesite_types/src/mastodon.rs b/lib/xesite_types/src/mastodon.rs
index 3b4eb2a..4cf1e96 100644
--- a/lib/xesite_types/src/mastodon.rs
+++ b/lib/xesite_types/src/mastodon.rs
@@ -4,193 +4,199 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct User {
#[serde(rename = "id")]
- id: String,
+ pub id: String,
#[serde(rename = "type")]
- user_type: String,
+ pub user_type: String,
#[serde(rename = "following")]
- following: String,
+ pub following: String,
#[serde(rename = "followers")]
- followers: String,
+ pub followers: String,
#[serde(rename = "inbox")]
- inbox: String,
+ pub inbox: String,
#[serde(rename = "outbox")]
- outbox: String,
+ pub outbox: String,
#[serde(rename = "featured")]
- featured: String,
+ pub featured: String,
#[serde(rename = "featuredTags")]
- featured_tags: String,
+ pub featured_tags: String,
#[serde(rename = "preferredUsername")]
- preferred_username: String,
+ pub preferred_username: String,
#[serde(rename = "name")]
- name: String,
+ pub name: String,
#[serde(rename = "summary")]
- summary: String,
+ pub summary: String,
#[serde(rename = "url")]
- url: String,
+ pub url: String,
#[serde(rename = "manuallyApprovesFollowers")]
- manually_approves_followers: bool,
+ pub manually_approves_followers: bool,
#[serde(rename = "discoverable")]
- discoverable: bool,
+ pub discoverable: bool,
#[serde(rename = "published")]
- published: String,
+ pub published: String,
#[serde(rename = "devices")]
- devices: String,
+ pub devices: String,
#[serde(rename = "icon")]
- icon: Icon,
+ pub icon: Icon,
#[serde(rename = "image")]
- image: Icon,
+ pub image: Icon,
}
#[derive(Serialize, Deserialize)]
pub struct Icon {
#[serde(rename = "type")]
- icon_type: String,
+ pub icon_type: String,
#[serde(rename = "mediaType")]
- media_type: String,
+ pub media_type: String,
#[serde(rename = "url")]
- url: String,
+ pub url: String,
}
#[derive(Serialize, Deserialize)]
pub struct Toot {
#[serde(rename = "id")]
- id: String,
+ pub id: String,
#[serde(rename = "type")]
- toot_type: String,
+ pub toot_type: String,
#[serde(rename = "inReplyTo")]
- in_reply_to: Option<String>,
+ pub in_reply_to: Option<String>,
#[serde(rename = "published")]
- published: DateTime<Utc>,
+ pub published: DateTime<Utc>,
#[serde(rename = "url")]
- url: String,
+ pub url: String,
#[serde(rename = "attributedTo")]
- attributed_to: String,
+ pub attributed_to: String,
#[serde(rename = "to")]
- to: Vec<String>,
+ pub to: Vec<String>,
#[serde(rename = "cc")]
- cc: Vec<String>,
+ pub cc: Vec<String>,
#[serde(rename = "sensitive")]
- sensitive: bool,
+ pub sensitive: bool,
#[serde(rename = "atomUri")]
- atom_uri: String,
+ pub atom_uri: String,
#[serde(rename = "inReplyToAtomUri")]
- in_reply_to_atom_uri: Option<String>,
+ pub in_reply_to_atom_uri: Option<String>,
#[serde(rename = "conversation")]
- conversation: String,
+ pub conversation: String,
#[serde(rename = "content")]
- content: String,
+ pub content: String,
#[serde(rename = "contentMap")]
- content_map: ContentMap,
+ pub content_map: ContentMap,
#[serde(rename = "attachment")]
- attachment: Vec<Attachment>,
+ pub attachment: Vec<Attachment>,
#[serde(rename = "tag")]
- tag: Vec<Tag>,
+ pub tag: Vec<Tag>,
#[serde(rename = "replies")]
- replies: Replies,
+ pub replies: Replies,
+}
+
+impl Toot {
+ pub fn content_text(&self) -> String {
+ html2text::from_read(std::io::Cursor::new(&self.content), 80)
+ }
}
#[derive(Serialize, Deserialize)]
pub struct Tag {
#[serde(rename = "type")]
- tag_type: String,
+ pub tag_type: String,
#[serde(rename = "href")]
- href: String,
+ pub href: String,
#[serde(rename = "name")]
- name: String,
+ pub name: String,
}
#[derive(Serialize, Deserialize)]
pub struct Attachment {
#[serde(rename = "type")]
- attachment_type: String,
+ pub attachment_type: String,
#[serde(rename = "mediaType")]
- media_type: String,
+ pub media_type: String,
#[serde(rename = "url")]
- url: String,
+ pub url: String,
#[serde(rename = "name")]
- name: Option<serde_json::Value>,
+ pub name: Option<String>,
#[serde(rename = "blurhash")]
- blurhash: String,
+ pub blurhash: String,
#[serde(rename = "width")]
- width: i64,
+ pub width: i64,
#[serde(rename = "height")]
- height: i64,
+ pub height: i64,
}
#[derive(Serialize, Deserialize)]
pub struct ContentMap {
#[serde(rename = "en")]
- en: String,
+ pub en: String,
}
#[derive(Serialize, Deserialize)]
pub struct Replies {
#[serde(rename = "id")]
- id: String,
+ pub id: String,
#[serde(rename = "type")]
- replies_type: String,
+ pub replies_type: String,
#[serde(rename = "first")]
- first: Page,
+ pub first: Page,
}
#[derive(Serialize, Deserialize)]
pub struct Page {
#[serde(rename = "type")]
- first_type: String,
+ pub first_type: String,
#[serde(rename = "next")]
- next: String,
+ pub next: String,
#[serde(rename = "partOf")]
- part_of: String,
+ pub part_of: String,
#[serde(rename = "items")]
- items: Vec<String>,
+ pub items: Vec<String>,
}
#[cfg(test)]