Use global way to get titles
This commit is contained in:
parent
5ae3fee3fd
commit
ac924536d9
9 changed files with 24 additions and 10 deletions
|
@ -108,7 +108,9 @@ from plugins import filters
|
|||
JINJA_FILTERS = {
|
||||
"datetime": filters.format_datetime,
|
||||
"category_find": filters.category_find,
|
||||
"limit": filters.limit
|
||||
"limit": filters.limit,
|
||||
"get_title": filters.get_title,
|
||||
"get_html_title": filters.get_html_title
|
||||
}
|
||||
|
||||
JINJA_ENVIRONMENT = {
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import iso8601
|
||||
|
||||
|
||||
def get_attribute(cls, attr, default=None):
|
||||
return getattr(cls, attr, default)
|
||||
|
||||
|
||||
def format_datetime(value):
|
||||
return iso8601.parse_date(str(value)).strftime("%x")
|
||||
|
||||
|
@ -19,3 +23,11 @@ def limit(line, length):
|
|||
return " ".join(line.split(" ")[:length]) + '...'
|
||||
elif isinstance(line, list):
|
||||
return line[:length]
|
||||
|
||||
|
||||
def get_title(instance):
|
||||
return get_attribute(instance, 'title') or (hasattr(instance, 'page') and get_attribute(instance.page, 'name')) or get_attribute(instance, 'name') or ''
|
||||
|
||||
|
||||
def get_html_title(instance):
|
||||
return get_attribute(instance, 'html_title') or get_title(instance)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block htmltitle %}
|
||||
{{ article.html_title or article.title }}
|
||||
{{ article|get_html_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block htmltitle %}
|
||||
{{ article.title }}
|
||||
{{ article|get_html_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block htmltitle %}
|
||||
{{ category.name|title }}
|
||||
{{ category|get_html_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
|
@ -30,7 +30,7 @@
|
|||
</div>
|
||||
<div class="media-body">
|
||||
<a href="/{{ article.url }}">
|
||||
<h4 class="media-heading">{{ article.title }}</h4>
|
||||
<h4 class="media-heading">{{ article|get_title }}</h4>
|
||||
</a>
|
||||
<p>{{ article.summary|striptags|e }}</p>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<header id="header" class="bg-primary image" data-image="{{ instance.image or (instance.page and instance.page.image) }}">
|
||||
<div class="header-content">
|
||||
<div class="header-content-inner">
|
||||
<h1>{{ instance.title or instance.name or (instance.page and instance.page.name) }}</h1>
|
||||
<h1>{{ instance|get_title }}</h1>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block htmltitle %}
|
||||
{{ page.title }}
|
||||
{{ page|get_html_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block htmltitle %}
|
||||
{{ page.html_title or page.title }}
|
||||
{{ page|get_html_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block htmltitle %}
|
||||
{{ article.title }}
|
||||
{{ article|get_html_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
|
@ -23,7 +23,7 @@
|
|||
<div class="container">
|
||||
<div class="btn-group">
|
||||
{% if article.download_link %}
|
||||
<a class="btn btn-primary btn-xl" href="{{ article.download_link }}">Download {{ article.title }}</a>
|
||||
<a class="btn btn-primary btn-xl" href="{{ article.download_link }}">Download {{ article|get_title }}</a>
|
||||
{% endif %}
|
||||
|
||||
{% if article.repo %}
|
||||
|
|
Reference in a new issue