]> git.gir.st - subscriptionfeed.git/blob - app/templates/macros.imp.j2
use new card.live property in typed_card
[subscriptionfeed.git] / app / templates / macros.imp.j2
1 {% set fallback_img = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 300' fill='%23fff'><circle r='30' cx='80' cy='150' fill='%23fff' stroke='%23000'/><circle r='30' cx='150' cy='150' fill='%23fff' stroke='%23000'/><circle r='30' cx='220' cy='150' fill='%23fff' stroke='%23000'/></svg>" %}
2
3 {% macro card_generic(link, thumbnail, title='', badge=None) -%}
4 <div class="card">
5 <div class="card-main">
6 <div class="thumb">
7 <img src="{{ thumbnail or fallback_img}}">
8 {% if badge is not none %}
9 <span class="badge">{{ badge | e }}</span>
10 {% endif %}
11 </div>
12 <div class="title">{{ title | e }}</div>
13 <a class="link-main" href="{{ link }}" title="{{ title | e }}"></a>
14 </div>
15 <div class="infobar">
16 {{ caller() }}
17 </div>
18 </div>
19 {%- endmacro %}
20
21 {% macro card(video_id, title='', advanced_text='', pinned="undefined", advanced_title='', post_url=None, badge=None) -%}
22 {% set caller_ = caller %}
23 {% call card_generic("/watch?v="~video_id, "https://i.ytimg.com/vi/"~video_id~"/mqdefault.jpg", title, badge) %}
24 {{ caller_() }}
25 <details class="advanced"><summary title="{{advanced_title}}">{{ advanced_text }}</summary>
26 <div class="details">
27 {% if post_url %}
28 {{ emoji_link("comments", post_url, False) }}
29 {%endif%}
30 {% if pinned != "undefined" %}
31 {{ emoji_button("pin", video_id, pinned, False) }}
32 {{ emoji_button("hide", video_id, False, False) }}
33 {%endif%}
34 {{ emoji_link("audio", video_id, False) }}
35 {{ emoji_link("raw", video_id, False) }}
36 {{ emoji_link("json", video_id, False) }}
37 </div></details>
38 {% endcall %}
39 {%- endmacro %}
40
41 {% macro typed_card(params) -%}
42 {% set c = params.content %}
43 {% if params.type == 'VIDEO' %}
44 {% set badge = 'LIVE' if c.live else c.length %}
45 {% call card(c.video_id, c.title, c.published, badge=badge) %}
46 {{ infobar_subscriptions(c.video_id, c.channel_id, c.author) }}
47 {% endcall %}
48 {% elif params.type == 'CHANNEL' %}
49 {% call card_generic("/channel/"~c.channel_id~"/", c.icons[c.icons.largest] if 'icons' in c else '', c.title) %}
50 <span class=channel>Channel</span>
51 <span class=advanced>{{ c.subscribers }}</span>
52 {% endcall %}
53 {% elif params.type == 'PLAYLIST' %}
54 {% call card_generic("/playlist?list="~c.playlist_id, "https://i.ytimg.com/vi/"~c.video_id~"/mqdefault.jpg", c.title) %}
55 <span class=channel>{{ infobar_subscriptions(None, c.channel_id, c.author) }}</span>
56 <span class=advanced>{{ c.n_videos }} videos</span>
57 {% endcall %}
58 {% elif params.type == 'WEBSITE' %}
59 {% call card_generic(c.url, c.icons[c.icons.largest] if 'icons' in c else '', c.title) %}
60 <span class=channel>{{ c.domain }}</span>
61 {% endcall %}
62 {% endif %}
63 {%- endmacro %}
64
65 {% macro dummycard() -%}
66 {% for _ in range(4) %}
67 <div class="dummy card"></div>
68 {% endfor %}
69 {%- endmacro %}
70
71 {# TODO: remove video_id parameter (unused) #}
72 {% macro infobar_subscriptions(video_id, channel_id, author) -%}
73 {% if channel_id is defined and channel_id is not none %}
74 <a class="info-main" href="/channel/{{ channel_id }}/">{{ author | e }}</a>
75 {% else %}
76 <span class="info-main">{{ author | e }}</span>
77 {% endif %}
78 {%- endmacro %}
79
80 {% macro emoji_button(action, subject, reverse=False, text=False) -%}
81 {% set icons = {
82 'pin': ['&#x1f4cc;&#xFE0F;', '&#x1f4cc;&#xFE0F;&#8416;'],
83 'hide': ['&#x1f4a8;&#xFE0F;', ''],
84 'subscribe': ['&#128221;&#xFE0F;', '&#128465;&#xFE0F;'],
85 } %}
86 {% set texts = {
87 'pin': ['pin to subscription feed', 'unpin'],
88 'hide': ['hide video', ''],
89 'subscribe': ['subscribe', 'unsubscribe'],
90 } %}
91 {% set actions = {
92 'pin': 'youtube.feed_post',
93 'hide': 'youtube.feed_post',
94 'subscribe': 'youtube.manage_subscriptions',
95 } %}
96 <form method=post action="{{ url_for(actions[action]) }}" class="emoji-form">
97 <input type="hidden" name="{{ 'un' if reverse }}{{ action }}" value="{{ subject }}">
98 <label title="{{ texts[action][reverse] }}">
99 <input type="submit" hidden>
100 <span class="emoji">{{ icons[action][reverse] }}</span>{#
101 #}<span class="notemoji">{{ texts[action][reverse] if text }}</span>
102 </label>
103 </form>
104 {%- endmacro %}
105 {% macro emoji_link(action, subject, text=False) -%}
106 {% set icons = {
107 'raw': '&#x1F39E;&#xFE0F;',
108 'json': '&#x1f4a1;',
109 'audio': '&#x1f3a7;',
110 'comments': '&#x1f4ac;',
111 } %}
112 {% set texts = {
113 'raw': 'show raw video',
114 'json': 'view json metadata',
115 'audio': 'listen to audio only',
116 'comments': 'view comments',
117 } %}
118 {% set actions = {
119 'raw': '/watch?v='~subject~'&show=raw',
120 'json': '/watch?v='~subject~'&show=json',
121 'audio': '/watch?v='~subject~'&show=audio',
122 'comments': 'https://old.reddit.com'~subject,
123 } %}
124 <a href="{{ actions[action] }}" title="{{ texts[action] }}">{#
125 #}<span class="emoji">{{ icons[action] }}</span>{#
126 #}<span class="notemoji">{{ texts[action] if text }}</span>
127 </a>
128 {%- endmacro %}
129
130 {% macro pagination(text, fields, direction) -%}
131 <a href="?{{ querystring_page(fields) }}" class="pagination {{ 'next' if direction > 0 else 'prev' }}">{{ text }}</a>
132 {%- endmacro %}
Imprint / Impressum