featured filter keywords out

This commit is contained in:
Christoph J. Scherr 2023-10-01 19:33:43 +02:00
parent 6ad7f0cfbd
commit a2fc4eb8b8
3 changed files with 71 additions and 66 deletions

View File

@ -68,6 +68,12 @@ class BlogPost(Searchable):
DATA_DIR = "/app/blog/data/articles"
DEFAULT_LANGS = {'en': False, 'de': False}
def key_words(self) -> bool:
"""
check if the post has keywords
"""
return False
def regenerate(self):
"""
regenerate a object
@ -123,6 +129,8 @@ class BlogPost(Searchable):
logger.debug(f"category of {self}: {category}")
self.category = category
self.keywords = None
except Exception as e:
logger.warning(
f"could not generate metadata {self.slug} from markdown: {e}")

View File

@ -1,39 +1,30 @@
{% load i18n %} {% get_current_language as LANGUAGE_CODE %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
<div class="container-lg mt-5">
<h4 class="">{% trans "Featured" %}</h4>
<div class="row row-cols-1 row-cols-md-5 my-4">
{% for post in featured_posts %}
<div class="card col m-2 p-0">
<a
class="text-reset link-offset-2 link-underline link-underline-opacity-0"
href=" {% url 'blog:post' post.category.slug post.slug %}"
>
<img
src="{{ post.thumbnail.url }}"
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
href=" {% url 'blog:post' post.category.slug post.slug %}">
<img src="{{ post.thumbnail.url }}"
class="card-img-top img-fluid"
style="max-height: 150px"
alt="thumbnail"
/>
alt="thumbnail" />
<div class="card-body" style="height: 100px">
{% if LANGUAGE_CODE == "de" %}
<h5 class="card-title">
{{ post.title_de }}<small class="text-body-secondary"
>{{ post.subtitle }}</small
>
{{ post.title_de }}<small class="text-body-secondary">{{ post.subtitle }}</small>
</h5>
<p class="card-text">{{ post.desc_de }}</p>
{% elif LANGUAGE_CODE == "en" %}
<h5 class="card-title">
{{ post.title_en }}<small class="text-body-secondary"
>{{ post.subtitle }}</small
>
{{ post.title_en }}<small class="text-body-secondary">{{ post.subtitle }}</small>
</h5>
<p class="card-text">{{ post.desc_en }}</p>
{% else %}
<h5 class="card-title">
{{ post.title_en }}<small class="text-body-secondary"
>{{ post.subtitle }}</small
>
{{ post.title_en }}<small class="text-body-secondary">{{ post.subtitle }}</small>
</h5>
<p class="card-text">{{ post.desc_en }}</p>
{% endif %}
@ -43,18 +34,21 @@
<li class="list-group-item">
{% translate "category" %}: <b>{{ post.category.name }}</b>
</li>
{% for keyword in post.keywords.all %} {% if LANGUAGE_CODE == "de"
%}
{% if post.has_keywords %}
{% for keyword in post.keywords.all %}
{% if LANGUAGE_CODE == "de" %}
<li class="list-group-item">{{ keyword.text_de }}</li>
{% elif LANGUAGE_CODE == "en" %}
<li class="list-group-item">{{ keyword.text_en }}</li>
{% else %}
<li class="list-group-item">{{ keyword.text_en }}</li>
{% endif %} {% endfor %}
{% endif %}
{% endfor %}
{% endif %}
</ul>
</div>
</a>
</div>
{% endfor %}
</div>
</div>
</div>

View File

@ -23,6 +23,7 @@ def change_lang(context, lang="de", *args, **kwargs):
logger.debug(f"changing lang from '{lang}'")
try:
path = context['request'].get_raw_uri()
url = path
try:
@ -36,3 +37,5 @@ def change_lang(context, lang="de", *args, **kwargs):
finally:
activate(lang)
return "%s" % url
except Exception as e:
logger.error(f"passing error chain: {e}")