mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-03-28 14:15:28 +00:00
Added display of image files to post description. (#5488)
This commit is contained in:
parent
85a4071a5c
commit
b8de9a518b
1 changed files with 9 additions and 4 deletions
|
@ -489,15 +489,20 @@ fn create_post_items(posts: Vec<PostView>, settings: &Settings) -> LemmyResult<V
|
||||||
// If its a url post, add it to the description
|
// If its a url post, add it to the description
|
||||||
// and see if we can parse it as a media enclosure.
|
// and see if we can parse it as a media enclosure.
|
||||||
let enclosure_opt = p.post.url.map(|url| {
|
let enclosure_opt = p.post.url.map(|url| {
|
||||||
let link_html = format!("<br><a href=\"{url}\">{url}</a>");
|
|
||||||
description.push_str(&link_html);
|
|
||||||
|
|
||||||
let mime_type = p
|
let mime_type = p
|
||||||
.post
|
.post
|
||||||
.url_content_type
|
.url_content_type
|
||||||
.unwrap_or_else(|| "application/octet-stream".to_string());
|
.unwrap_or_else(|| "application/octet-stream".to_string());
|
||||||
let mut enclosure_bld = EnclosureBuilder::default();
|
|
||||||
|
|
||||||
|
// If the url directly links to an image, wrap it in an <img> tag for display.
|
||||||
|
let link_html = if mime_type.starts_with("image/") {
|
||||||
|
format!("<br><a href=\"{url}\"><img src=\"{url}\"/></a>")
|
||||||
|
} else {
|
||||||
|
format!("<br><a href=\"{url}\">{url}</a>")
|
||||||
|
};
|
||||||
|
description.push_str(&link_html);
|
||||||
|
|
||||||
|
let mut enclosure_bld = EnclosureBuilder::default();
|
||||||
enclosure_bld.url(url.as_str().to_string());
|
enclosure_bld.url(url.as_str().to_string());
|
||||||
enclosure_bld.mime_type(mime_type);
|
enclosure_bld.mime_type(mime_type);
|
||||||
enclosure_bld.length("0".to_string());
|
enclosure_bld.length("0".to_string());
|
||||||
|
|
Loading…
Reference in a new issue