Browse Source

Fix invalid CSS class on hierarchical topic tags

When a topic tag was using the hierarchy (for something like
"science.biology"), it would set an invalid class on the tag label,
because it would include the period(s), which can't be used in CSS
classes. This fixes it so that periods will be replaced with dashes.
merge-requests/55/head
Deimos 6 years ago
parent
commit
e89b0751ba
  1. 6
      tildes/tildes/templates/includes/topic_tags.jinja2
  2. 18
      tildes/tildes/templates/macros/topics.jinja2

6
tildes/tildes/templates/includes/topic_tags.jinja2

@ -1,11 +1,11 @@
{# Copyright (c) 2018 Tildes contributors <code@tildes.net> #} {# Copyright (c) 2018 Tildes contributors <code@tildes.net> #}
{# SPDX-License-Identifier: AGPL-3.0-or-later #} {# SPDX-License-Identifier: AGPL-3.0-or-later #}
{% from 'macros/topics.jinja2' import topic_tag %}
<ul class="topic-tags"> <ul class="topic-tags">
{% for tag in topic.tags %} {% for tag in topic.tags %}
<li class="label label-topic-tag label-topic-tag-{{ tag.replace(' ', '_') }}">
<a href="/~{{ topic.group.path }}?tag={{ tag.replace(' ', '_') }}">{{ tag }}</a>
</li>
{{ topic_tag(tag, "/~"~topic.group.path~"?tag="~tag.replace(' ', '_')) }}
{% else %} {% else %}
<li class="label label-topic-tag">No tags</li> <li class="label label-topic-tag">No tags</li>
{% endfor %} {% endfor %}

18
tildes/tildes/templates/macros/topics.jinja2

@ -40,13 +40,11 @@
{% if topic.tags %} {% if topic.tags %}
<ul class="topic-tags"> <ul class="topic-tags">
{% for tag in topic.tags %} {% for tag in topic.tags %}
<li class="label label-topic-tag label-topic-tag-{{ tag.replace(' ', '_') }}">
{% if request.matched_route.name in ('home', 'group') %}
<a href="{{ request.current_listing_normal_url({'tag': tag.replace(' ', '_')}) }}">{{ tag }}</a>
{% if request.matched_route_name in ('home', 'group') %}
{{ topic_tag(tag, request.current_listing_normal_url({'tag': tag.replace(' ', '_')})) }}
{% else %} {% else %}
{{ tag }}
{{ topic_tag(tag) }}
{% endif %} {% endif %}
</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
@ -171,3 +169,13 @@
{{ classes|join(' ') }} {{ classes|join(' ') }}
{% endmacro %} {% endmacro %}
{% macro topic_tag(tag, link=None) %}
<li class="label label-topic-tag label-topic-tag-{{ tag.replace(' ', '_').replace('.', '-') }}">
{% if link %}
<a href="{{ link }}">{{ tag }}</a>
{% else %}
{{ tag }}
{% endif %}
</li>
{% endmacro %}
Loading…
Cancel
Save