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

CONCD-725 dynamic TOC links #2310

Merged
merged 1 commit into from
Mar 8, 2024
Merged
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
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