Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/fp 1439 yearly site theme for texascale #490

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions taccsite_cms/templates/djangocms_blog/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
</style>
{% endif %}

{% block content_assets %}
<link rel="stylesheet" href="{% static 'site_cms/css/build/app.blog.css' %}">
{% endblock content_assets %}

<div class="app app-blog
{% if not settings.TACC_BLOG_SHOW_CATEGORIES %}no-categories{% endif %}
{% if not settings.TACC_BLOG_SHOW_TAGS %}no-tags{% endif %}
Expand Down
49 changes: 49 additions & 0 deletions taccsite_cms/templatetags/get_url_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re

from django import template
from urllib.parse import urlparse

register = template.Library()

@register.filter
def get_url_match(path, pattern):
"""
Custom Template Filter `get_url_match`

Use: Render string that matches given pattern from current page URL.

Load custom filter into template:
{% load get_url_match %}

Template inline usage:
{# given path '.../2019/...', does nothing #}
{% if path|get_url_match:"/20\d\d/" %}
{# condition evaluates to False #}
{% endif %}

{# given path '.../2020/...', does something #}
{% if path|get_url_match:"/20\d\d/" %}
{# condition evaluates to True #}
{% endif %}

{# given path '.../2021/...', prints complete match #}
{% with year_path=path|get_url_match:"/20\d\d/" %}
<pre>{{ year_path }}</pre> {# prints complete match #}
{% endwith %}

{# given path '.../2022/...', prints matched content #}
{% with year_slug=path|get_url_match:"/(20\d\d)/" %}
<pre>{{ year_slug }}</pre> {# prints match within the (…) #}
{% endwith %}
"""
result = re.search(pattern, path)

if result:
try:
match = result.group(1)
except IndexError:
match = result[0]
else:
match = False

return match