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

View File

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

View File

@ -23,16 +23,19 @@ def change_lang(context, lang="de", *args, **kwargs):
logger.debug(f"changing lang from '{lang}'") logger.debug(f"changing lang from '{lang}'")
path = context['request'].get_raw_uri()
url = path
try: try:
cur_lang: str = get_language() path = context['request'].get_raw_uri()
url = re.sub(f"/{cur_lang}/", f"/{lang}/", url) url = path
try:
cur_lang: str = get_language()
url = re.sub(f"/{cur_lang}/", f"/{lang}/", url)
except Exception as e:
logger.error(f"exception while building language switcher form: {e}")
logger.debug(f"this is the context: {context}")
finally:
activate(lang)
return "%s" % url
except Exception as e: except Exception as e:
logger.error(f"exception while building language switcher form: {e}") logger.error(f"passing error chain: {e}")
logger.debug(f"this is the context: {context}")
finally:
activate(lang)
return "%s" % url