]> git.gir.st - subscriptionfeed.git/blob - app/templates/macros.imp.j2
add final / to /channel/ urls in templates
[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 {% call card(c.video_id, c.title, c.published, badge=c.length) %}
45 {{ infobar_subscriptions(c.video_id, c.channel_id, c.author) }}
46 {% endcall %}
47 {% elif params.type == 'CHANNEL' %}
48 {% call card_generic("/channel/"~c.channel_id~"/", c.icons[c.icons.largest] if 'icons' in c else '', c.title) %}
49 <span class=channel>Channel</span>
50 <span class=advanced>{{ c.subscribers }}</span>
51 {% endcall %}
52 {% elif params.type == 'PLAYLIST' %}
53 {% call card_generic("/playlist?list="~c.playlist_id, "https://i.ytimg.com/vi/"~c.video_id~"/mqdefault.jpg", c.title) %}
54 <span class=channel>{{ c.author }}</span>
55 <span class=advanced>{{ c.n_videos }} videos</span>
56 {% endcall %}
57 {% elif params.type == 'WEBSITE' %}
58 {% call card_generic(c.url, c.icons[c.icons.largest] if 'icons' in c else '', c.title) %}
59 <span class=channel>{{ c.domain }}</span>
60 {% endcall %}
61 {% endif %}
62 {%- endmacro %}
63
64 {% macro dummycard() -%}
65 {% for _ in range(4) %}
66 <div class="dummy card"></div>
67 {% endfor %}
68 {%- endmacro %}
69
70 {% macro infobar_subscriptions(video_id, channel_id, author) -%}
71 {% if channel_id is defined and channel_id is not none %}
72 <a class="info-main" href="/channel/{{ channel_id }}/">{{ author | e }}</a>
73 {% else %}
74 <span class="info-main">{{ author | e }}</span>
75 {% endif %}
76 {%- endmacro %}
77
78 {% macro emoji_button(action, subject, reverse=False, text=False) -%}
79 {% set icons = {
80 'pin': ['&#x1f4cc;&#xFE0F;', '&#x1f4cc;&#xFE0F;&#8416;'],
81 'hide': ['&#x1f4a8;&#xFE0F;', ''],
82 'subscribe': ['&#128221;&#xFE0F;', '&#128465;&#xFE0F;'],
83 } %}
84 {% set texts = {
85 'pin': ['pin to subscription feed', 'unpin'],
86 'hide': ['hide video', ''],
87 'subscribe': ['subscribe', 'unsubscribe'],
88 } %}
89 {% set actions = {
90 'pin': 'youtube.feed_post',
91 'hide': 'youtube.feed_post',
92 'subscribe': 'youtube.manage_subscriptions',
93 } %}
94 <form method=post action="{{ url_for(actions[action]) }}" class="emoji-form">
95 <input type="hidden" name="{{ 'un' if reverse }}{{ action }}" value="{{ subject }}">
96 <label title="{{ texts[action][reverse] }}">
97 <input type="submit" hidden>
98 <span class="emoji">{{ icons[action][reverse] }}</span>{#
99 #}<span class="notemoji">{{ texts[action][reverse] if text }}</span>
100 </label>
101 </form>
102 {%- endmacro %}
103 {% macro emoji_link(action, subject, text=False) -%}
104 {% set icons = {
105 'raw': '&#x1F39E;&#xFE0F;',
106 'json': '&#x1f4a1;',
107 'audio': '&#x1f3a7;',
108 'comments': '&#x1f4ac;',
109 } %}
110 {% set texts = {
111 'raw': 'show raw video',
112 'json': 'view json metadata',
113 'audio': 'listen to audio only',
114 'comments': 'view comments',
115 } %}
116 {% set actions = {
117 'raw': '/watch?v='~subject~'&show=raw',
118 'json': '/watch?v='~subject~'&show=json',
119 'audio': '/watch?v='~subject~'&show=audio',
120 'comments': 'https://old.reddit.com'~subject,
121 } %}
122 <a href="{{ actions[action] }}" title="{{ texts[action] }}">{#
123 #}<span class="emoji">{{ icons[action] }}</span>{#
124 #}<span class="notemoji">{{ texts[action] if text }}</span>
125 </a>
126 {%- endmacro %}
127
128 {% macro pagination(text, fields, direction) -%}
129 <a href="?{{ querystring_page(fields) }}" class="pagination {{ 'next' if direction > 0 else 'prev' }}">{{ text }}</a>
130 {%- endmacro %}
Imprint / Impressum