diff options
Diffstat (limited to 'pydis_site')
-rw-r--r-- | pydis_site/apps/content/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/content/templatetags/str_methods.py | 21 | ||||
-rw-r--r-- | pydis_site/apps/content/tests/helpers.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/content/tests/test_templatetags.py | 12 | ||||
-rw-r--r-- | pydis_site/apps/content/tests/test_views.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/content/views/page_category.py | 15 | ||||
-rw-r--r-- | pydis_site/templates/content/dropdown.html | 6 |
7 files changed, 15 insertions, 43 deletions
diff --git a/pydis_site/apps/content/templatetags/__init__.py b/pydis_site/apps/content/templatetags/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/pydis_site/apps/content/templatetags/__init__.py +++ /dev/null diff --git a/pydis_site/apps/content/templatetags/str_methods.py b/pydis_site/apps/content/templatetags/str_methods.py deleted file mode 100644 index 91db3e72..00000000 --- a/pydis_site/apps/content/templatetags/str_methods.py +++ /dev/null @@ -1,21 +0,0 @@ -from django import template -from django.template.defaultfilters import stringfilter - -register = template.Library() - - [email protected](is_safe=True) -@stringfilter -def replace_hyphens(value: str, replacement: str) -> str: - """ - Simple filter to replace hyphens with the specified replacement string. - - Usage: - - ```django - {% for name_with_hyphens in name_list %} - {{ name_with_hyphens|replace_hyphen:" " }} - {% endfor %} - ``` - """ - return value.replace("-", replacement) diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py index 202dee42..29140375 100644 --- a/pydis_site/apps/content/tests/helpers.py +++ b/pydis_site/apps/content/tests/helpers.py @@ -87,5 +87,5 @@ class MockPagesTestCase(TestCase): # See: https://jmcgeheeiv.github.io/pyfakefs/release/usage.html#os-temporary-directories self.fs.create_file("tmp/_info.yml", contents=CATEGORY_INFO) self.fs.create_file("tmp.md", contents=MARKDOWN_WITH_METADATA) - self.fs.create_file("tmp/category/_info.yml", contents=MARKDOWN_WITH_METADATA) + self.fs.create_file("tmp/category/_info.yml", contents=CATEGORY_INFO) self.fs.create_dir("tmp/category/subcategory_without_info") diff --git a/pydis_site/apps/content/tests/test_templatetags.py b/pydis_site/apps/content/tests/test_templatetags.py deleted file mode 100644 index 1147bd88..00000000 --- a/pydis_site/apps/content/tests/test_templatetags.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.test import TestCase - -from pydis_site.apps.content.templatetags.str_methods import replace_hyphens - - -class TestTemplateTags(TestCase): - """Tests for the custom template tags in the content app.""" - - def test_replace_hyphens(self): - self.assertEquals(replace_hyphens("word-with-hyphens", " "), "word with hyphens") - self.assertEquals(replace_hyphens("---", ""), "") - self.assertEquals(replace_hyphens("hi----", "A"), "hiAAAA") diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py index 36d771a1..74d38f78 100644 --- a/pydis_site/apps/content/tests/test_views.py +++ b/pydis_site/apps/content/tests/test_views.py @@ -161,7 +161,7 @@ class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): "page_title": PARSED_METADATA["title"], "page_description": PARSED_METADATA["description"], "relevant_links": PARSED_METADATA["relevant_links"], - "subarticles": ["category"] + "subarticles": [{"path": "category", "name": "Category Name"}] } for key, expected_value in expected_page_context.items(): with self.subTest(): diff --git a/pydis_site/apps/content/views/page_category.py b/pydis_site/apps/content/views/page_category.py index b31814f7..4031fde2 100644 --- a/pydis_site/apps/content/views/page_category.py +++ b/pydis_site/apps/content/views/page_category.py @@ -1,6 +1,7 @@ import typing as t from pathlib import Path +import frontmatter from django.conf import settings from django.http import Http404 from django.views.generic import TemplateView @@ -49,10 +50,16 @@ class PageOrCategoryView(TemplateView): # Add subarticle information for dropdown menu if the page is also a category if self.page_path.is_file() and self.category_path.is_dir(): - context["subarticles"] = [ - path.stem for path in self.category_path.iterdir() - if path.suffix != ".yml" - ] + context["subarticles"] = [] + for entry in self.category_path.iterdir(): + entry_info = {"path": entry.stem} + if entry.suffix == ".md": + entry_info["name"] = frontmatter.load(entry).metadata["title"] + elif entry.is_dir(): + entry_info["name"] = utils.get_category(entry)["title"] + else: + continue + context["subarticles"].append(entry_info) context["breadcrumb_items"] = [ { diff --git a/pydis_site/templates/content/dropdown.html b/pydis_site/templates/content/dropdown.html index 25a68e88..c9491f3a 100644 --- a/pydis_site/templates/content/dropdown.html +++ b/pydis_site/templates/content/dropdown.html @@ -1,5 +1,3 @@ -{% load str_methods %} - <script> document.addEventListener("DOMContentLoaded", () => { const dropdown = document.querySelector("#dropdown"); @@ -28,8 +26,8 @@ </div> <div class="dropdown-menu" id="subarticle-menu" role="menu"> <div class="dropdown-content"> - {% for page in subarticles|dictsort:0 %} - <a href="{{page}}" class="dropdown-item">{{ page.title|replace_hyphens:" " }}</a> + {% for page in subarticles|dictsort:"name" %} + <a href="{{ page.path }}" class="dropdown-item">{{ page.name }}</a> {% endfor %} </div> </div> |