Inline videos/gifs for card view (#107)

* Basic gallery support

* Inline videos for card view
This commit is contained in:
robrobinbin 2021-02-08 01:22:14 +01:00 committed by GitHub
parent cf45d53fdd
commit 7edca18f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 1 deletions

View File

@ -102,6 +102,7 @@ async fn parse_post(json: &serde_json::Value) -> Post {
url: format_url(val(post, "thumbnail").as_str()), url: format_url(val(post, "thumbnail").as_str()),
width: post["data"]["thumbnail_width"].as_i64().unwrap_or_default(), width: post["data"]["thumbnail_width"].as_i64().unwrap_or_default(),
height: post["data"]["thumbnail_height"].as_i64().unwrap_or_default(), height: post["data"]["thumbnail_height"].as_i64().unwrap_or_default(),
poster: "".to_string(),
}, },
flair: Flair { flair: Flair {
flair_parts: parse_rich_flair( flair_parts: parse_rich_flair(

View File

@ -44,6 +44,7 @@ pub struct Media {
pub url: String, pub url: String,
pub width: i64, pub width: i64,
pub height: i64, pub height: i64,
pub poster: String,
} }
pub struct GalleryMedia { pub struct GalleryMedia {
@ -255,6 +256,7 @@ pub async fn media(data: &Value) -> (String, Media, Vec<GalleryMedia>) {
url, url,
width: data["preview"]["images"][0]["source"]["width"].as_i64().unwrap_or_default(), width: data["preview"]["images"][0]["source"]["width"].as_i64().unwrap_or_default(),
height: data["preview"]["images"][0]["source"]["height"].as_i64().unwrap_or_default(), height: data["preview"]["images"][0]["source"]["height"].as_i64().unwrap_or_default(),
poster: format_url(data["preview"]["images"][0]["source"]["url"].as_str().unwrap_or_default()),
}, },
gallery, gallery,
) )
@ -384,6 +386,7 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
url: format_url(val(post, "thumbnail").as_str()), url: format_url(val(post, "thumbnail").as_str()),
width: post["data"]["thumbnail_width"].as_i64().unwrap_or_default(), width: post["data"]["thumbnail_width"].as_i64().unwrap_or_default(),
height: post["data"]["thumbnail_height"].as_i64().unwrap_or_default(), height: post["data"]["thumbnail_height"].as_i64().unwrap_or_default(),
poster: "".to_string(),
}, },
media, media,
domain: val(post, "domain"), domain: val(post, "domain"),

View File

@ -641,6 +641,13 @@ a.search_subreddit:hover {
max-width: calc(100% - 40px); max-width: calc(100% - 40px);
grid-area: post_media; grid-area: post_media;
margin: 15px auto 5px auto; margin: 15px auto 5px auto;
height: auto;
}
.post_media_video.short {
max-height: 512px;
width: auto;
} }
.post_media_image.short svg, .post_media_image.short img{ .post_media_image.short svg, .post_media_image.short img{

View File

@ -77,7 +77,7 @@
</svg> </svg>
</a> </a>
{% else if post.post_type == "video" || post.post_type == "gif" %} {% else if post.post_type == "video" || post.post_type == "gif" %}
<video class="post_media_video" src="{{ post.media.url }}" controls autoplay loop></video> <video class="post_media_video" src="{{ post.media.url }}" controls autoplay loop><a href={{ post.media.url }}>Video</a></video>
{% else if post.post_type == "gallery" %} {% else if post.post_type == "gallery" %}
<div class="gallery"> <div class="gallery">
{% for image in post.gallery -%} {% for image in post.gallery -%}

View File

@ -86,6 +86,10 @@
</desc> </desc>
</svg> </svg>
</a> </a>
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %}
<video class="post_media_video short" src="{{ post.media.url }}" width="{{ post.media.width }}px" height="{{ post.media.height }}px" controls loop><a href={{ post.media.url }}>Video</a></video>
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "video" %}
<video class="post_media_video short" src="{{ post.media.url }}" width="{{ post.media.width }}px" height="{{ post.media.height }}px" poster="{{ post.media.poster }}" preload=none controls><a href={{ post.media.url }}>Video</a></video>
{% else if post.post_type != "self" %} {% else if post.post_type != "self" %}
<a class="post_thumbnail {% if post.thumbnail.url.is_empty() %}no_thumbnail{% endif %}" href="{% if post.post_type == "link" %}{{ post.media.url }}{% else %}{{ post.permalink }}{% endif %}"> <a class="post_thumbnail {% if post.thumbnail.url.is_empty() %}no_thumbnail{% endif %}" href="{% if post.post_type == "link" %}{{ post.media.url }}{% else %}{{ post.permalink }}{% endif %}">
{% if post.thumbnail.url.is_empty() %} {% if post.thumbnail.url.is_empty() %}