Skip to content

Commit

Permalink
CONCD-725 dynamic TOC links (#2310)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasarkar authored Mar 8, 2024
1 parent 3844a24 commit 7547de0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 5 additions & 7 deletions concordia/templates/static-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ <h1 class="my-3">{{ title }}</h1>
<div class="col-3">
<div class="nav flex-column help-center">
<h4>Instructions</h4>
<a class="nav-link" href="{% url 'welcome-guide' %}">Get started</a>
<a class="nav-link{% if title == 'Transcription: Basic rules' %} active{% endif %}" href="{% url 'transcription-basic-rules' %}">Transcription: Basic Rules</a>
<a class="nav-link{% if title == 'Transcription: Things to avoid' %} active{% endif %}" href="{% url 'transcription-things-to-avoid' %}">Transcription: Things to avoid</a>
<a class="nav-link{% if title == 'Transcription: Printed text & images' %} active{% endif %}" href="{% url 'transcription-printed-text-images' %}">Transcription: Printed text & images</a>
<a class="nav-link{% if title == 'Transcription: Unusual text' %} active{% endif %}" href="{% url 'transcription-unusual-text' %}">Transcription: Unusual text</a>
<a class="nav-link{% if title == 'How to Review' %} active{% endif %}" href="{% url 'how-to-review' %}">How to review</a>
<a class="nav-link{% if title == 'How to Tag' %} active{% endif %}" href="{% url 'how-to-tag' %}">How to tag</a>
{% for link in toc %}
<a class="nav-link{% if title|lower == link.0|lower %} active{% endif %}" href="{% url link.1 %}">
{{ link.0 }}
</a>
{% endfor %}
<span lang="es">
<a class="nav-link" href="/help-center/how-to-transcribe-esp/">Instrucciones en español</a>
</span>
Expand Down
13 changes: 12 additions & 1 deletion concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from django.urls import reverse, reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.http import http_date
from django.utils.text import slugify
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import cache_control, never_cache
Expand Down Expand Up @@ -188,12 +189,22 @@ def simple_page(request, path=None):
"breadcrumbs": breadcrumbs,
}

guides = Guide.objects
try:
guide = Guide.objects.get(title__iexact=page.title)
guide = guides.get(title__iexact=page.title)
html = "".join((page.body, guide.body))
ctx["add_navigation"] = True
except Guide.DoesNotExist:
html = page.body
if page.title == "Get started":
ctx["add_navigation"] = True
if "add_navigation" in ctx:
links = [
("Get started", "welcome-guide"),
]
for guide in guides.all():
links.append((guide.title, slugify(guide.title)))
ctx["toc"] = links
ctx["body"] = md.convert(html)

resp = render(request, "static-page.html", ctx)
Expand Down

0 comments on commit 7547de0

Please sign in to comment.