microblog.pub/templates/utils.html

324 lines
13 KiB
HTML
Raw Normal View History

2018-06-23 05:01:31 -05:00
{% macro display_actor_inline(follower, size=50) -%}
2018-07-22 05:53:09 -05:00
{% if follower and follower.id %}
2018-07-22 05:42:36 -05:00
<a class="actor-box" href="{{follower | url_or_id | get_url }}" style="clear:both;">
<span style="float:left;padding-right:15px;">
{% if not follower.icon %}
2018-06-23 05:01:31 -05:00
<img class="actor-icon" src="/static/nopic.png" style="width:{{ size }}px">
{% else %}
2018-07-04 18:08:39 -05:00
<img class="actor-icon" src="{{ follower.icon.url | get_actor_icon_url(size) }}" style="width:{{ size }}px;">{% endif %}
</span>
2018-06-22 02:35:18 -05:00
<div class="actor-inline">
<div style="font-weight:bold">{{ follower.name or follower.preferredUsername }}</div>
2018-07-22 05:42:36 -05:00
<small class="lcolor">@{{ follower.preferredUsername }}@{{ follower | url_or_id | get_url | domain }}</small>
</div>
</a>
2018-07-22 05:53:09 -05:00
{% endif %}
{%- endmacro %}
2018-07-01 05:49:16 -05:00
{% macro display_note(obj, perma=False, ui=False, likes=[], shares=[], meta={}, no_color=False) -%}
2019-04-15 14:20:14 -05:00
2018-07-19 18:12:02 -05:00
{% if meta.actor %}
2019-04-15 14:20:14 -05:00
{% set actor = meta.actor %}
2018-07-19 18:12:02 -05:00
{% else %}
2019-04-15 14:20:14 -05:00
{% set actor = obj.attributedTo | get_actor %}
2018-07-19 18:12:02 -05:00
{% endif %}
2018-07-29 13:24:46 -05:00
2019-04-14 12:17:54 -05:00
{% if session.logged_in %}
2019-04-15 14:20:14 -05:00
{% set perma_id = obj.id | permalink_id %}
2019-04-14 12:17:54 -05:00
2019-04-15 14:20:14 -05:00
{% if request.args.get('older_than') %}
{% set redir = request.path + "?older_than=" + request.args.get('older_than') + "#activity-" + perma_id %}
{% elif request.args.get('newer_than') %}
{% set redir = request.path + "?newer_than=" + request.args.get('newer_than') + "#activity-" + perma_id %}
{% else %}
{% set redir = request.path + "#activity-" + perma_id %}
{% endif %}
2019-04-14 12:17:54 -05:00
2019-04-15 14:20:14 -05:00
{% set aid = obj.id | quote_plus %}
{% endif %}
2019-04-14 12:17:54 -05:00
2018-07-21 16:16:40 -05:00
<div class="note-box">
2018-06-29 15:16:26 -05:00
<div class="note h-entry" id="activity-{{ obj.id | permalink_id }}">
2018-05-18 13:41:41 -05:00
<div class="h-card p-author">
2018-07-22 05:42:36 -05:00
<a class="u-url u-uid no-hover" href="{{ actor | url_or_id | get_url }}"><img class="u-photo" src="{% if not actor.icon %}/static/nopic.png{% else %}{{ actor.icon.url | get_actor_icon_url(50) }}{% endif %}">
2018-05-18 13:41:41 -05:00
</a>
<data class="p-name" value="{{ actor.name or actor.preferredUsername }}"></data>
2018-05-18 13:41:41 -05:00
</div>
<div class="note-wrapper">
2018-07-29 13:24:46 -05:00
<div style="clear:both;height:20px;">
2018-07-29 12:38:59 -05:00
<a href="{{ actor | url_or_id | get_url }}" style="margin:0;text-decoration:none;margin: 0;text-decoration: none;display: block;width: 80%;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;float: left;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong>
2018-09-02 12:51:40 -05:00
<span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor | url_or_id | get_url | domain }}</span>{% else %}{{ actor | url_or_id | get_url | domain }}{% endif %}</span></a>
2018-05-18 13:41:41 -05:00
{% if not perma %}
2018-07-29 12:38:59 -05:00
<span style="float:right;width: 20%;text-align: right;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;display: block;">
2018-07-30 02:41:04 -05:00
<a rel="noopener" class="u-url u-uid note-permalink l" href="{{ obj | url_or_id | get_url }}">
2018-06-29 15:16:26 -05:00
<time class="dt-published" title="{{ obj.published }}" datetime="{{ obj.published }}">{{ obj.published | format_timeago }}</time></a>
2018-05-18 13:41:41 -05:00
</span>
{% endif %}
2018-07-29 13:24:46 -05:00
</div>
2019-04-15 14:20:14 -05:00
2018-06-29 15:16:26 -05:00
{% if obj.summary %}<p class="p-summary">{{ obj.summary | clean }}</p>{% endif %}
2018-09-02 12:43:09 -05:00
{% if obj | has_type('Video') %}
<div class="note-video">
<video controls preload="metadata" src="{{ obj.url | get_video_link }}" width="480">
</video>
</div>
{% endif %}
2019-04-15 14:20:14 -05:00
<div class="note-container{% if perma %} perma{%endif%} p-name e-content">
2018-07-29 13:24:46 -05:00
{% if obj | has_type('Article') %}
2019-04-15 14:20:14 -05:00
{{ obj.name }} <a href="{{ obj | url_or_id | get_url }}">{{ obj | url_or_id | get_url }}</a>
{% elif obj | has_type('Question') %}
2019-04-15 14:20:14 -05:00
{{ obj.content | clean | safe }}
{% if obj.id | is_from_outbox or (meta.question_replies and (obj.closed or meta.voted_for)) %}
<ul style="list-style:none;padding:0;">
{% set total_votes = meta.question_replies %}
{% for oneOf in obj.oneOf %}
{% set pct = 0 %}
{% if total_votes > 0 %}
{% set cnt = oneOf.name | get_answer_count(meta) %}
{% set pct = cnt * 100.0 / total_votes %}
{% endif %}
<li class="answer">
<span class="answer-bar color-menu-background" style="width:{{pct}}%;"></span>
<span class="answer-text">
<span>{{ '%0.0f'| format(pct) }}%</span>
{{ oneOf.name }}
</span>
</li>
{% endfor %}
2019-04-14 12:17:54 -05:00
</ul>
<p><small>
2019-04-14 13:16:04 -05:00
{% if obj.closed or obj.endTime | gtnow %}
2019-04-15 14:20:14 -05:00
Ended {{ obj.endTime | format_timeago }} with <strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %}.
2019-04-14 12:17:54 -05:00
{% else %}
2019-04-15 14:20:14 -05:00
Ends {{ obj.endTime | format_timeago }} (<strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %} as of now).
2019-04-14 12:17:54 -05:00
{% endif %}
</small></p>
{% else %}
<ul style="list-style:none;padding:0;">
{% for oneOf in obj.oneOf %}
2019-04-14 12:17:54 -05:00
<li class="answer">
<span class="answer-text">
{% if not meta.voted_for and not obj.endTime | gtnow %}
<span><form action="/api/vote" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
<input type="hidden" name="id" value="{{ obj.id }}">
<input type="hidden" name="choice" value="{{ oneOf.name }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">vote</button>
</form></span>
{% else %}
<span>???</span>
{% endif %}
{{ oneOf.name }} {% if oneOf.name == meta.voted_for %}(your vote){% endif %}
</span>
</li>
{% endfor %}
2019-04-14 12:17:54 -05:00
<p><small>{% if obj.endTime | gtnow %}This question ended {{ obj.endTime | format_timeago }}.</small></p>
{% else %}This question ends {{ obj.endTime | format_timeago }}{% endif %}
</small></p>
</ul>
2019-04-14 12:17:54 -05:00
{% endif %}
2018-07-29 13:24:46 -05:00
{% else %}
2018-06-29 15:16:26 -05:00
{{ obj.content | clean | safe }}
2018-07-29 13:24:46 -05:00
{% endif %}
2018-05-18 13:41:41 -05:00
</div>
2018-07-29 13:24:46 -05:00
{% if obj.attachment and obj | has_type('Note') %}
2018-05-18 13:41:41 -05:00
<div style="padding:20px 0;">
2018-06-29 15:16:26 -05:00
{% if obj.attachment | not_only_imgs %}
2018-09-02 12:43:09 -05:00
<h3 class="l">Attachments</h3>
<ul style="padding:0;">
2018-05-18 13:41:41 -05:00
{% endif %}
2018-06-29 15:16:26 -05:00
{% for a in obj.attachment %}
{% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
<a href="{{ a.url | get_attachment_url(None) }}"><img src="{{a.url | get_attachment_url(720) }}" class="img-attachment"></a>
2018-09-02 12:43:09 -05:00
{% elif (a.mediaType and a.mediaType.startswith("video/")) %}
<li><video controls preload="metadata" src="{{ a.url }}" width="480"></video></li>
2018-05-18 13:41:41 -05:00
{% else %}
2018-07-23 16:56:22 -05:00
<li><a href="{{a.url }}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li>
2018-05-18 13:41:41 -05:00
{% endif %}
{% endfor %}
2018-06-29 15:16:26 -05:00
{% if obj.attachment | not_only_imgs %}
2018-05-18 13:41:41 -05:00
</ul>
{% endif %}
</div>
{% endif %}
2018-07-21 16:16:40 -05:00
2018-07-29 13:24:46 -05:00
{% if meta and meta.og_metadata and obj | has_type('Note') %}
2018-07-21 16:16:40 -05:00
{% for og in meta.og_metadata %}
2018-08-05 06:55:48 -05:00
{% if og.url %}
2018-07-21 16:16:40 -05:00
<a href="{{ og.url }}" class="og-link" style="margin:30px 0;clear:both;display: flex;">
<div>
<img style="width:100px;border-radius:3px;" src="{{ og.image | get_og_image_url }}">
</div>
<div style="padding:0 20px;">
<strong>{{ og.title }}</strong>
<p>{{ og.description | truncate(80) }}</p>
<small>{{ og.site_name }}</small>
</div>
</a>
2018-08-05 06:55:48 -05:00
{% endif %}
2018-07-21 16:16:40 -05:00
{% endfor %}
{% endif %}
2018-05-18 13:41:41 -05:00
<div class="bottom-bar">
2018-06-29 15:16:26 -05:00
{% if perma %}<span class="perma-item">{{ obj.published | format_time }}</span>
2018-07-15 14:33:59 -05:00
{% if not (obj.id | is_from_outbox) %}
2018-07-24 15:45:03 -05:00
<a class ="bar-item" href="{{ obj | url_or_id | get_url }}">permalink</a>
2018-07-15 14:12:57 -05:00
{% endif %}
2018-07-15 14:33:59 -05:00
{% else %}
2018-07-24 15:45:03 -05:00
<a class ="bar-item" href="{{ obj | url_or_id | get_url }}">permalink</a>
2018-07-15 14:12:57 -05:00
{% endif %}
2018-07-15 14:12:57 -05:00
{% if meta.count_reply and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_reply }}</strong> replies</a>
2018-07-14 05:29:46 -05:00
{% elif meta.count_reply and session.logged_in %}
<a class ="bar-item" href="/admin/thread?oid={{aid}}"><strong>{{ meta.count_reply }}</strong> replies</a>{% endif %}
{% if not perma and meta.count_boost and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_boost }}</strong> boosts</a>{% endif %}
{% if not perma and meta.count_like and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_like }}</strong> likes</a>{% endif %}
2018-07-14 05:29:46 -05:00
{% if session.logged_in %}
{% if ui%}
2018-07-14 05:14:08 -05:00
2018-06-29 15:16:26 -05:00
{% if meta.boosted %}
<form action="/api/undo" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
2018-06-29 15:16:26 -05:00
<input type="hidden" name="id" value="{{ meta.boosted }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">unboost</button>
</form>
2018-05-18 13:41:41 -05:00
{% else %}
<form action="/api/boost" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
2018-06-29 15:16:26 -05:00
<input type="hidden" name="id" value="{{ obj.id }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">boost</button>
</form>
2018-05-18 13:41:41 -05:00
{% endif %}
2018-06-29 15:16:26 -05:00
{% if meta.liked %}
<form action="/api/undo" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
2018-06-29 15:16:26 -05:00
<input type="hidden" name="id" value="{{ meta.liked }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">unlike</button>
</form>
2018-05-18 13:41:41 -05:00
{% else %}
<form action="/api/like" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
2018-06-29 15:16:26 -05:00
<input type="hidden" name="id" value="{{ obj.id }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">like</button>
</form>
2018-05-18 13:41:41 -05:00
{% endif %}
{% endif %}
2018-06-04 11:53:44 -05:00
2018-06-29 15:16:26 -05:00
{% if obj.id | is_from_outbox %}
2018-06-04 11:53:44 -05:00
<form action="/api/note/delete" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
2018-06-29 15:16:26 -05:00
<input type="hidden" name="id" value="{{ obj.id }}">
2018-06-04 11:53:44 -05:00
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">delete</button>
</form>
{% if meta.pinned %}
<form action="/api/note/unpin" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
<input type="hidden" name="id" value="{{ obj.id }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">unpin</button>
</form>
{% else %}
<form action="/api/note/pin" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
<input type="hidden" name="id" value="{{ obj.id }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">pin</button>
</form>
{% endif %}
2018-06-04 11:53:44 -05:00
{% else %}
<form action="/api/block" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
2018-06-29 15:16:26 -05:00
<input type="hidden" name="actor" value="{{ actor.id }}">
2018-06-04 11:53:44 -05:00
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="bar-item">block</button>
</form>
{% endif %}
<a class="bar-item" href="/admin/new?reply={{ aid }}">reply</a>
2018-06-04 11:53:44 -05:00
{% endif %}
2018-05-18 13:41:41 -05:00
</div>
2018-06-03 16:36:16 -05:00
{% if likes or shares %}
<div style="padding-top:20px;" class="pure-g">
{% if likes %}
2018-06-03 16:36:16 -05:00
<div class="pure-u-1-2">
2018-08-28 15:14:48 -05:00
<h4 style="font-weight:normal"><strong>{{ likes|length }}</strong> likes</h4>{% for like in likes %}
{{ display_actor_inline(like) }}
{% endfor %}
</div>
{% endif %}
2018-06-03 16:36:16 -05:00
{% if shares %}
<div class="pure-u-1-2">
2018-08-28 15:14:48 -05:00
<h4 style="font-weight:normal"><strong>{{ shares|length }}</strong> boosts</h4>{% for boost in shares %}
2018-06-03 16:36:16 -05:00
{{ display_actor_inline(boost) }}
{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
</div>
</div>
2018-07-21 16:16:40 -05:00
</div>
2018-05-18 13:41:41 -05:00
{%- endmacro %}
2018-06-03 14:28:06 -05:00
2018-06-03 16:36:16 -05:00
{% macro display_thread(thread, likes=[], shares=[]) -%}
2018-06-03 14:28:06 -05:00
{% for reply in thread %}
{% if reply._requested %}
2018-06-29 15:16:26 -05:00
{{ display_note(reply.activity.object, perma=True, ui=False, likes=likes, shares=shares, meta=reply.meta) }}
2018-06-03 14:28:06 -05:00
{% else %}
2018-06-29 15:16:26 -05:00
{{ display_note(reply.activity.object, perma=False, ui=True, meta=reply.meta) }}
2018-06-03 14:28:06 -05:00
{% endif %}
{% endfor %}
{% endmacro -%}
2018-07-06 16:53:33 -05:00
{% macro display_pagination(older_than, newer_than) -%}
<div class="clear">
{% if older_than %}
2018-07-24 16:44:16 -05:00
<a href="{{ config.BASE_URL }}{{ request.path }}?older_than={{older_than}}{% if request.args.get('limit') %}&limit={{request.args.get('limit')}}{% endif %}" rel="next" class="older-link lcolor"><span class="pcolor">🡨</span> Older</a>
2018-07-06 16:53:33 -05:00
{% endif %}
{% if newer_than %}
2018-07-24 16:44:16 -05:00
<a href="{{ config.BASE_URL }}{{ request.path }}?newer_than={{newer_than}}{% if request.args.get('limit') %}&limit={{request.args.get('limit')}}{% endif %}" rel="prev" class="newer-link lcolor">Newer <span class="pcolor">🡪</span></a>
2018-07-06 16:53:33 -05:00
{% endif %}
</div>
{% endmacro -%}
{% macro display_pagination_links(older_than, newer_than) -%}
{% if older_than %}<link rel="next" href="{{ config.BASE_URL }}{{ request.path }}?older_than={{older_than}}">{% endif %}
{% if newer_than %}<link rel="prev" href="{{ config.BASE_URL }}{{ request.path }}?newer_than={{newer_than}}">{% endif %}
{% endmacro -%}