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 = {
|
JINJA_FILTERS = {
|
||||||
"datetime": filters.format_datetime,
|
"datetime": filters.format_datetime,
|
||||||
"category_find": filters.category_find,
|
"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 = {
|
JINJA_ENVIRONMENT = {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import iso8601
|
import iso8601
|
||||||
|
|
||||||
|
|
||||||
|
def get_attribute(cls, attr, default=None):
|
||||||
|
return getattr(cls, attr, default)
|
||||||
|
|
||||||
|
|
||||||
def format_datetime(value):
|
def format_datetime(value):
|
||||||
return iso8601.parse_date(str(value)).strftime("%x")
|
return iso8601.parse_date(str(value)).strftime("%x")
|
||||||
|
|
||||||
|
@ -19,3 +23,11 @@ def limit(line, length):
|
||||||
return " ".join(line.split(" ")[:length]) + '...'
|
return " ".join(line.split(" ")[:length]) + '...'
|
||||||
elif isinstance(line, list):
|
elif isinstance(line, list):
|
||||||
return line[:length]
|
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" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block htmltitle %}
|
{% block htmltitle %}
|
||||||
{{ article.html_title or article.title }}
|
{{ article|get_html_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block metadata %}
|
{% block metadata %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block htmltitle %}
|
{% block htmltitle %}
|
||||||
{{ article.title }}
|
{{ article|get_html_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block metadata %}
|
{% block metadata %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block htmltitle %}
|
{% block htmltitle %}
|
||||||
{{ category.name|title }}
|
{{ category|get_html_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block metadata %}
|
{% block metadata %}
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="media-body">
|
<div class="media-body">
|
||||||
<a href="/{{ article.url }}">
|
<a href="/{{ article.url }}">
|
||||||
<h4 class="media-heading">{{ article.title }}</h4>
|
<h4 class="media-heading">{{ article|get_title }}</h4>
|
||||||
</a>
|
</a>
|
||||||
<p>{{ article.summary|striptags|e }}</p>
|
<p>{{ article.summary|striptags|e }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<header id="header" class="bg-primary image" data-image="{{ instance.image or (instance.page and instance.page.image) }}">
|
<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">
|
||||||
<div class="header-content-inner">
|
<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>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block htmltitle %}
|
{% block htmltitle %}
|
||||||
{{ page.title }}
|
{{ page|get_html_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block metadata %}
|
{% block metadata %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block htmltitle %}
|
{% block htmltitle %}
|
||||||
{{ page.html_title or page.title }}
|
{{ page|get_html_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block metadata %}
|
{% block metadata %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block htmltitle %}
|
{% block htmltitle %}
|
||||||
{{ article.title }}
|
{{ article|get_html_title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block metadata %}
|
{% block metadata %}
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
{% if article.download_link %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% if article.repo %}
|
{% if article.repo %}
|
||||||
|
|
Reference in a new issue