add get_text
template filter
returns object's `content` or `name`, the first is set, or an empty string. some objects don't have `content`, don't let templates rely on it
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
{% extends "layout.html" %}
|
||||
{% import 'utils.html' as utils %}
|
||||
{% block title %}{{ config.NAME }}: "{{ note.activity.object.content | html2plaintext | trim | truncate(50) }}"{% endblock %}
|
||||
{% block title %}{{ config.NAME }}{{ note.activity.object | get_text | html2plaintext | trim | truncate(50) }}"{% endblock %}
|
||||
{% block header %}
|
||||
<meta name="description" content="{{ note.activity.object.content | html2plaintext | trim | truncate(50) }}">
|
||||
<meta name="description" content="{{ note.activity.object | get_text | html2plaintext | trim | truncate(50) }}">
|
||||
|
||||
<meta content="article" property="og:type" />
|
||||
<meta content="{{ note.activity.object.url }}" property="og:url" />
|
||||
<meta content="{{ config.USERNAME }} microblog" property="og:site_name" />
|
||||
<meta content="{{ config.USERNAME }}" property="og:title" />
|
||||
<meta content="{{ note.activity.object.content | html2plaintext | trim | truncate(50) }}" property="og:description" />
|
||||
<meta content="{{ note.activity.object | get_text | html2plaintext | trim | truncate(50) }}" property="og:description" />
|
||||
<meta content="{{ me.icon.url }}" property="og:image" />
|
||||
<meta content="200" property="og:image:width" />
|
||||
<meta content="200" property="og:image:height" />
|
||||
|
@@ -198,7 +198,7 @@
|
||||
|
||||
|
||||
{% else %}
|
||||
{{ obj.content | update_inline_imgs | clean | replace_custom_emojis(obj) | code_highlight | safe }}
|
||||
{{ obj | get_text | update_inline_imgs | clean | replace_custom_emojis(obj) | code_highlight | safe }}
|
||||
{% endif %}
|
||||
|
||||
{% if obj | has_place %}
|
||||
|
@@ -403,6 +403,14 @@ def get_video_link(data):
|
||||
return data
|
||||
return None
|
||||
|
||||
@filters.app_template_filter()
|
||||
def get_text(data):
|
||||
"""return first in 'content', 'name' or ''"""
|
||||
for _t in ("content", "name"):
|
||||
if _t in data:
|
||||
return data[_t]
|
||||
return ""
|
||||
|
||||
|
||||
@filters.app_template_filter()
|
||||
def has_type(doc, _types):
|
||||
|
Reference in New Issue
Block a user