microblog.pub/templates/utils.html

170 lines
5.9 KiB
HTML
Raw Normal View History

2018-06-23 05:01:31 -05:00
{% macro display_actor_inline(follower, size=50) -%}
<a class="actor-box" href="{{follower.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-06-23 05:01:31 -05:00
<img class="actor-icon" src="{{ follower.icon.url }}" 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>
<small>@{{ follower.preferredUsername }}@{{ follower.url | domain }}</small>
</div>
</a>
{%- endmacro %}
2018-05-18 13:41:41 -05:00
2018-06-29 15:16:26 -05:00
{% macro display_note(obj, perma=False, ui=False, likes=[], shares=[], meta={}) -%}
{% set actor = obj.attributedTo | get_actor %}
<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">
<a class="u-url u-uid no-hover" href="{{ actor.url }}"><img class="u-photo" src="{% if not actor.icon %}/static/nopic.png{% else %}{{ actor.icon.url }}{% endif %}">
</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">
<a href="{{ actor.url }}" style="margin:0;text-decoration:none;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong> <span class="l">@{{ actor.preferredUsername }}@{{ actor.url | domain }}</span></a>
{% if not perma %}
<span style="float:right">
2018-06-29 15:16:26 -05:00
<a rel="noopener" class="u-url u-uid note-permalink l" href="{{ obj.url }}">
<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-06-29 15:16:26 -05:00
{% if obj.summary %}<p class="p-summary">{{ obj.summary | clean }}</p>{% endif %}
2018-05-18 13:41:41 -05:00
<div class="note-container{% if perma %} perma{%endif%} p-name e-content">
2018-06-29 15:16:26 -05:00
{{ obj.content | clean | safe }}
2018-05-18 13:41:41 -05:00
</div>
2018-06-29 15:16:26 -05:00
{% if obj.attachment %}
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-05-18 13:41:41 -05:00
<h3 class="l">Attachment</h3>
<ul>
{% endif %}
2018-06-29 15:16:26 -05:00
{% for a in obj.attachment %}
2018-05-18 13:41:41 -05:00
{% if a.url | is_img %}
<img src="{{a.url}}" class="img-attachment">
{% else %}
<li><a href="{{a.url}}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li>
{% 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 %}
<div class="bottom-bar">
2018-06-29 15:16:26 -05:00
{% if perma %}<span class="perma-item">{{ obj.published | format_time }}</span>
2018-06-03 16:36:16 -05:00
{% else %}
2018-06-29 15:16:26 -05:00
<a class ="bar-item" href="{{ obj.url }}">permalink</a>
2018-06-29 15:16:26 -05:00
{% if meta.count_reply %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_reply }}</strong> replies</a>{% endif %}
{% if meta.count_boost %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_boost }}</strong> boosts</a>{% endif %}
{% if meta.count_like %}<a class ="bar-item" href="{{ obj.url }}"><strong>{{ meta.count_like }}</strong> likes</a>{% endif %}
2018-06-03 16:36:16 -05:00
{% endif %}
2018-06-03 14:28:06 -05:00
{% if ui and session.logged_in %}
2018-06-29 15:16:26 -05:00
{% set aid = obj.id | quote_plus %}
2018-05-18 13:41:41 -05:00
<a class="bar-item" href="/new?reply={{ aid }}">reply</a>
2018-06-29 15:16:26 -05:00
{% set perma_id = obj.id | permalink_id %}
{% set redir = request.path + "#activity-" + perma_id %}
2018-05-18 13:41:41 -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
{% if session.logged_in %}
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>
{% 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 %}
{% 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-06-29 15:16:26 -05:00
<h4 style="font-weight:normal"><strong>{{ meta.count_like }}</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-06-29 15:16:26 -05:00
<h4 style="font-weight:normal"><strong>{{ meta.count_boost }}</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-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 -%}