Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline videos/gifs for card view #107

Merged
merged 4 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async fn parse_post(json: &serde_json::Value) -> Post {
url: format_url(val(post, "thumbnail").as_str()),
width: post["data"]["thumbnail_width"].as_i64().unwrap_or_default(),
height: post["data"]["thumbnail_height"].as_i64().unwrap_or_default(),
poster: "".to_string(),
},
flair: Flair {
flair_parts: parse_rich_flair(
Expand Down
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Media {
pub url: String,
pub width: i64,
pub height: i64,
pub poster: String,
}

pub struct GalleryMedia {
Expand Down Expand Up @@ -255,6 +256,7 @@ pub async fn media(data: &Value) -> (String, Media, Vec<GalleryMedia>) {
url,
width: data["preview"]["images"][0]["source"]["width"].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,
)
Expand Down Expand Up @@ -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()),
width: post["data"]["thumbnail_width"].as_i64().unwrap_or_default(),
height: post["data"]["thumbnail_height"].as_i64().unwrap_or_default(),
poster: "".to_string(),
},
media,
domain: val(post, "domain"),
Expand Down
7 changes: 7 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,13 @@ a.search_subreddit:hover {
max-width: calc(100% - 40px);
grid-area: post_media;
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{
Expand Down
2 changes: 1 addition & 1 deletion templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</svg>
</a>
{% 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" %}
<div class="gallery">
{% for image in post.gallery -%}
Expand Down
4 changes: 4 additions & 0 deletions templates/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
</desc>
</svg>
</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" %}
<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() %}
Expand Down