Back to Libreddit

{{ post.title }} {% if post.flair.flair_parts.len() > 0 %} {% call render_flair(post.flair.flair_parts) %} {% endif %} {% if post.flags.nsfw %} NSFW{% endif %}

templates/utils.html

3.0.07.0 KB
Original Source

{% macro options(current, values, default) -%} {% for value in values %} {{ format!("{}{}", value.get(0..1).unwrap_or_default().to_uppercase(), value.get(1..).unwrap_or_default()) }} {% endfor %} {%- endmacro %} {% macro sort(root, methods, selected) -%} {% for method in methods %} {{ format!("{}{}", method.get(0..1).unwrap_or_default().to_uppercase(), method.get(1..).unwrap_or_default()) }} {% endfor %} {%- endmacro %} {% macro search(root, search) -%}

{% if root != "/r/" && !root.is_empty() %} in {{ root }} {% endif %} → {%- endmacro %} {% macro render_flair(flair_parts) -%} {% for flair_part in flair_parts.clone() %}{% if flair_part.flair_part_type == "emoji" %}{% else if flair_part.flair_part_type == "text" && !flair_part.value.is_empty() %}{{ flair_part.value }}{% endif %}{% endfor %} {%- endmacro %} {% macro sub_list(current) -%} #Feeds

MAIN FEEDS

HomePopularAll {% if prefs.subscriptions.len() > 0 %}

REDDIT FEEDS

{% for sub in prefs.subscriptions %} {{ sub }} {% endfor %} {% endif %} {%- endmacro %} {% macro render_hls_notification(redirect_url) -%} {% if post.post_type == "video" && !post.media.alt_url.is_empty() && prefs.hide_hls_notification != "on" %}

Enable HLS to view with audio, or disable this notification

{% endif %} {%- endmacro %} {% macro post(post) -%}

r/{{ post.community }}u/{{ post.author.name }} {% if post.author.flair.flair_parts.len() > 0 %} {% call render_flair(post.author.flair.flair_parts) %} {% endif %} •{{ post.rel_time }} {% if !post.awards.is_empty() && prefs.hide_awards != "on" %} • {% for award in post.awards.clone() %} {{ award.count }} {% endfor %} {% endif %}

{{ post.title }} {% if post.flair.flair_parts.len() > 0 %} {% call render_flair(post.flair.flair_parts) %} {% endif %} {% if post.flags.nsfw %} NSFW{% endif %}

{% if post.post_type == "image" %}

{% else if post.post_type == "video" || post.post_type == "gif" %} {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %} 0 && post.media.height > 0 %}width="{{ post.media.width }}" height="{{ post.media.height }}"{% endif %} poster="{{ post.media.poster }}" preload="none" controls> {% else %} Video {% call render_hls_notification(post.permalink[1..]) %} {% endif %} {% else if post.post_type == "gallery" %} {% for image in post.gallery -%} {{ image.caption }} {% if image.outbound_url.len() > 0 %} {{ image.outbound_url }} {% endif %} {%- endfor %} {% else if post.post_type == "link" %} {{ post.media.url }} {% endif %} {{ post.body|safe }}

{{ post.score.0 }} Upvotes {% call poll(post) %}

{{ post.upvote_ratio }}% Upvoted

{%- endmacro %} {% macro external_reddit_link(permalink) %} {% for dev_type in ["desktop", "mobile"] %}- reddit {% if prefs.disable_visit_reddit_confirmation != "on" %} {% call visit_reddit_confirmation(permalink) %} {% endif %} {% endfor %} {% endmacro %} {% macro post_in_list(post) -%}

{% let community -%} {% if post.community.starts_with("u_") -%} {% let community = format!("u/{}", &post.community[2..]) -%} {% else -%} {% let community = format!("r/{}", post.community) -%} {% endif -%} {{ community }}u/{{ post.author.name }}•{{ post.rel_time }} {% if !post.awards.is_empty() && prefs.hide_awards != "on" %} {% for award in post.awards.clone() %} {% endfor %} {% endif %}

{% if post.flair.flair_parts.len() > 0 %} {% call render_flair(post.flair.flair_parts) %} {% endif %} {{ post.title }}{% if post.flags.nsfw %} NSFW{% endif %}

{% if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "image" %}

{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %} 0 && post.media.height > 0 %}width="{{ post.media.width }}" height="{{ post.media.height }}"{% endif %} poster="{{ post.media.poster }}" preload="none" controls loop {% if prefs.autoplay_videos == "on" %}autoplay{% endif %}>Video {% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "video" %} {% if prefs.use_hls == "on" && !post.media.alt_url.is_empty() %} 0 && post.media.height > 0 %}width="{{ post.media.width }}" height="{{ post.media.height }}"{% endif %} poster="{{ post.media.poster }}" controls preload="none"> {% else %} 0 && post.media.height > 0 %}width="{{ post.media.width }}" height="{{ post.media.height }}"{% endif %} poster="{{ post.media.poster }}" preload="none" controls {% if prefs.autoplay_videos == "on" %}autoplay{% endif %}>Video {% call render_hls_notification(format!("{}%23{}", &self.url[1..].replace("&", "%26").replace("+", "%2B"), post.id)) %} {% endif %} {% else if post.post_type != "self" %} {% if post.thumbnail.url.is_empty() %} Thumbnail {% else %} {% endif %} {% if post.post_type == "link" %}{{ post.domain }}{% else %}{{ post.post_type }}{% endif %} {% endif %} {{ post.score.0 }} Upvotes

{{ post.body|safe }} {% call poll(post) %} {{ post.comments.0 }} {% if post.comments.1 == "1" %}comment{% else %}comments{% endif %}

{%- endmacro %} {% macro visit_reddit_confirmation(url) -%}

You are about to leave Libreddit

Do you want to continue?

https://www.reddit.com{{ url }}

No, go back!Yes, take me to Reddit

{%- endmacro %} {% macro poll(post) -%} {% match post.poll %} {% when Some with (poll) %} {% let widest = poll.most_votes() %} {{ poll.total_vote_count }} votes,{{ poll.voting_end_timestamp.0 }} {% for option in poll.poll_options %} {# Posts without vote_count (all open polls) will show up without votes. This is an issue with Reddit API, it doesn't work on Old Reddit either. #} {% match option.vote_count %} {% when Some with (vote_count) %} {% if vote_count.eq(widest) || widest == 0 %}

{% else %}

{% endif %} {{ vote_count }} {% when None %}

{% endmatch %} {{ option.text }} {% endfor %} {% when None %} {% endmatch %} {%- endmacro %}