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