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