diff --git a/plume-models/src/medias.rs b/plume-models/src/medias.rs index 8b220a0..6f83486 100644 --- a/plume-models/src/medias.rs +++ b/plume-models/src/medias.rs @@ -44,28 +44,32 @@ impl Media { pub fn to_json(&self, conn: &Connection) -> serde_json::Value { let mut json = serde_json::to_value(self).expect("Media::to_json: serialization error"); let url = self.url(conn); - let (preview, html, md) = match self.file_path.rsplitn(2, '.').next().expect("Media::to_json: extension error") { + let (cat, preview, html, md) = match self.file_path.rsplitn(2, '.').next().expect("Media::to_json: extension error") { "png" | "jpg" | "jpeg" | "gif" | "svg" => ( + "image", format!("\"{}\"", url, self.alt_text, self.alt_text), format!("\"{}\"", url, self.alt_text, self.alt_text), format!("![{}]({})", self.alt_text, url), ), "mp3" | "wav" | "flac" => ( + "audio", format!("", url, self.alt_text), format!("", url, self.alt_text), format!("", url, self.alt_text), ), "mp4" | "avi" | "webm" | "mov" => ( + "video", format!("", url, self.alt_text), format!("", url, self.alt_text), format!("", url, self.alt_text), ), - _ => (String::new(), String::new(), String::new()) + _ => ("unknown", String::new(), String::new(), String::new()) }; json["html_preview"] = json!(preview); json["html"] = json!(html); json["url"] = json!(url); json["md"] = json!(md); + json["category"] = json!(cat); json } diff --git a/templates/posts/new.html.tera b/templates/posts/new.html.tera index b7f3d6a..796ab91 100644 --- a/templates/posts/new.html.tera +++ b/templates/posts/new.html.tera @@ -39,9 +39,11 @@