From acf7880e233faeb91ce2eeb59855f40b6e7db3e0 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 25 Mar 2021 16:36:16 +0800 Subject: Refactor content app tests. The tests uses pyfakefs to simulate a fake filesystem that is reused over the content app tests. Test coverage for the app is brought to 100%. --- pydis_site/apps/content/tests/helpers.py | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 pydis_site/apps/content/tests/helpers.py (limited to 'pydis_site/apps/content/tests/helpers.py') diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py new file mode 100644 index 00000000..4e0cca34 --- /dev/null +++ b/pydis_site/apps/content/tests/helpers.py @@ -0,0 +1,84 @@ +from pyfakefs.fake_filesystem_unittest import TestCase + +# Valid markdown content with YAML metadata +MARKDOWN_WITH_METADATA = """ +--- +title: TestTitle +description: TestDescription +relevant_links: + Python Discord: https://pythondiscord.com + Discord: https://discord.com +--- +# This is a header. +""" + +MARKDOWN_WITHOUT_METADATA = """#This is a header.""" + +# Valid YAML in a _info.yml file +CATEGORY_INFO = """ +name: Category Name +description: Description +""" + +# The HTML generated from the above markdown data +PARSED_HTML = ( + '

This is a header.' + '

' +) + +# The YAML metadata parsed from the above markdown data +PARSED_METADATA = { + "title": "TestTitle", "description": "TestDescription", + "relevant_links": { + "Python Discord": "https://pythondiscord.com", + "Discord": "https://discord.com" + } +} + +# The YAML data parsed from the above _info.yml file +PARSED_CATEGORY_INFO = {"name": "Category Name", "description": "Description"} + + +class MockPagesTestCase(TestCase): + """ + TestCase with a fake filesystem for testing. + + Structure: + ├── _info.yml + ├── root.md + ├── root_without_metadata.md + ├── not_a_page.md + ├── tmp + |   ├── _info.yml + |   └── category_without_info + └── category +    ├── _info.yml +    ├── with_metadata.md +    └── subcategory +    ├── with_metadata.md +       └── without_metadata.md + """ + + def setUp(self): + """Create the fake filesystem.""" + self.setUpPyfakefs() + + self.fs.create_file("_info.yml", contents=CATEGORY_INFO) + self.fs.create_file("root.md", contents=MARKDOWN_WITH_METADATA) + self.fs.create_file("root_without_metadata.md", contents=MARKDOWN_WITHOUT_METADATA) + self.fs.create_file("not_a_page.md/_info.yml", contents=CATEGORY_INFO) + self.fs.create_file("category/_info.yml", contents=CATEGORY_INFO) + self.fs.create_file("category/with_metadata.md", contents=MARKDOWN_WITH_METADATA) + self.fs.create_file("category/subcategory/_info.yml", contents=CATEGORY_INFO) + self.fs.create_file( + "category/subcategory/with_metadata.md", contents=MARKDOWN_WITH_METADATA + ) + self.fs.create_file( + "category/subcategory/without_metadata.md", contents=MARKDOWN_WITHOUT_METADATA + ) + + # There is always a `tmp` directory in the filesystem, so make it a category + # for testing purposes. + # 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_dir("tmp/category_without_info") -- cgit v1.2.3 From bc90ff58fd97b5b90a5adb6820f340fdbb9e2b1a Mon Sep 17 00:00:00 2001 From: kosayoda Date: Mon, 29 Mar 2021 18:43:20 +0800 Subject: Fix failing tests. --- pydis_site/apps/content/tests/helpers.py | 4 ++-- pydis_site/apps/content/tests/test_utils.py | 2 +- pydis_site/apps/content/tests/test_views.py | 29 +++++++++++++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'pydis_site/apps/content/tests/helpers.py') diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py index 4e0cca34..be91b95a 100644 --- a/pydis_site/apps/content/tests/helpers.py +++ b/pydis_site/apps/content/tests/helpers.py @@ -16,7 +16,7 @@ MARKDOWN_WITHOUT_METADATA = """#This is a header.""" # Valid YAML in a _info.yml file CATEGORY_INFO = """ -name: Category Name +title: Category Name description: Description """ @@ -36,7 +36,7 @@ PARSED_METADATA = { } # The YAML data parsed from the above _info.yml file -PARSED_CATEGORY_INFO = {"name": "Category Name", "description": "Description"} +PARSED_CATEGORY_INFO = {"title": "Category Name", "description": "Description"} class MockPagesTestCase(TestCase): diff --git a/pydis_site/apps/content/tests/test_utils.py b/pydis_site/apps/content/tests/test_utils.py index 58175d6f..658a6d4e 100644 --- a/pydis_site/apps/content/tests/test_utils.py +++ b/pydis_site/apps/content/tests/test_utils.py @@ -14,7 +14,7 @@ class GetCategoryTests(MockPagesTestCase): def test_get_valid_category(self): result = utils.get_category(Path("category")) - self.assertEqual(result, {"name": "Category Name", "description": "Description"}) + self.assertEqual(result, {"title": "Category Name", "description": "Description"}) def test_get_nonexistent_category(self): with self.assertRaises(Http404): diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py index 560378bc..46a0f7da 100644 --- a/pydis_site/apps/content/tests/test_views.py +++ b/pydis_site/apps/content/tests/test_views.py @@ -17,6 +17,23 @@ with fake_filesystem_unittest.Patcher() as _: BASE_PATH = Path(".") +def patch_dispatch_attributes(view: PageOrCategoryView, location: str) -> None: + """ + Set the attributes set in the `dispatch` method manually. + + This is necessary because it is never automatically called during tests. + """ + view.location = Path(location) + + # URL location on the filesystem + view.full_location = view.location + + # Possible places to find page content information + view.category_page_path = view.full_location.joinpath(view.location.stem).with_suffix(".md") + view.category_path = view.full_location + view.page_path = view.full_location.with_suffix(".md") + + @override_settings(PAGES_PATH=BASE_PATH) class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): """Tests for the PageOrCategoryView class.""" @@ -63,13 +80,13 @@ class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): for path, expected_template in cases: with self.subTest(path=path, expected_template=expected_template): - self.ViewClass.full_location = Path(path) + patch_dispatch_attributes(self.ViewClass, path) self.assertEqual(self.ViewClass.get_template_names(), [expected_template]) def test_get_template_names_with_nonexistent_paths_returns_404(self): for path in ("invalid", "another_invalid", "nonexistent"): with self.subTest(path=path): - self.ViewClass.full_location = Path(path) + patch_dispatch_attributes(self.ViewClass, path) with self.assertRaises(Http404): self.ViewClass.get_template_names() @@ -120,7 +137,7 @@ class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): "page_description", PARSED_CATEGORY_INFO["description"] ), - ("Context includes page title", "page_title", PARSED_CATEGORY_INFO["name"]), + ("Context includes page title", "page_title", PARSED_CATEGORY_INFO["title"]), ] context = self.ViewClass.get_context_data() @@ -138,8 +155,8 @@ class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): self.assertEquals( context["breadcrumb_items"], [ - {"name": PARSED_CATEGORY_INFO["name"], "path": "."}, - {"name": PARSED_CATEGORY_INFO["name"], "path": "category"}, - {"name": PARSED_CATEGORY_INFO["name"], "path": "category/subcategory"}, + {"name": PARSED_CATEGORY_INFO["title"], "path": "."}, + {"name": PARSED_CATEGORY_INFO["title"], "path": "category"}, + {"name": PARSED_CATEGORY_INFO["title"], "path": "category/subcategory"}, ] ) -- cgit v1.2.3 From 61fafa2e42a7eaff28f9d30853b044949d299798 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Mon, 29 Mar 2021 19:12:51 +0800 Subject: Add new tests to achieve full coverage. --- pydis_site/apps/content/tests/helpers.py | 13 ++++++++++--- pydis_site/apps/content/tests/test_utils.py | 8 +++++--- pydis_site/apps/content/tests/test_views.py | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) (limited to 'pydis_site/apps/content/tests/helpers.py') diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py index be91b95a..59cd3bd6 100644 --- a/pydis_site/apps/content/tests/helpers.py +++ b/pydis_site/apps/content/tests/helpers.py @@ -8,6 +8,7 @@ description: TestDescription relevant_links: Python Discord: https://pythondiscord.com Discord: https://discord.com +toc: 0 --- # This is a header. """ @@ -32,7 +33,8 @@ PARSED_METADATA = { "relevant_links": { "Python Discord": "https://pythondiscord.com", "Discord": "https://discord.com" - } + }, + "toc": 0 } # The YAML data parsed from the above _info.yml file @@ -50,7 +52,10 @@ class MockPagesTestCase(TestCase): ├── not_a_page.md ├── tmp |   ├── _info.yml - |   └── category_without_info + |   ├── tmp.md + |   └── category + |    ├── _info.yml + |      └── subcategory_without_info └── category    ├── _info.yml    ├── with_metadata.md @@ -81,4 +86,6 @@ class MockPagesTestCase(TestCase): # for testing purposes. # 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_dir("tmp/category_without_info") + self.fs.create_file("tmp/tmp.md", contents=MARKDOWN_WITH_METADATA) + self.fs.create_file("tmp/category/_info.yml", contents=MARKDOWN_WITH_METADATA) + self.fs.create_dir("tmp/category/subcategory_without_info") diff --git a/pydis_site/apps/content/tests/test_utils.py b/pydis_site/apps/content/tests/test_utils.py index 658a6d4e..6612e44c 100644 --- a/pydis_site/apps/content/tests/test_utils.py +++ b/pydis_site/apps/content/tests/test_utils.py @@ -28,7 +28,7 @@ class GetCategoryTests(MockPagesTestCase): def test_get_category_without_info_yml(self): # Categories should provide an _info.yml file with self.assertRaises(FileNotFoundError): - utils.get_category(Path("tmp/category_without_info")) + utils.get_category(Path("tmp/category/subcategory_without_info")) class GetCategoriesTests(MockPagesTestCase): @@ -73,10 +73,12 @@ class GetPageTests(MockPagesTestCase): """Tests for the get_page function.""" def test_get_page(self): + # TOC is a special case because the markdown converter outputs the TOC as HTML + updated_metadata = {**PARSED_METADATA, "toc": '
\n
    \n
    \n'} cases = [ - ("Root page with metadata", "root.md", PARSED_HTML, PARSED_METADATA), + ("Root page with metadata", "root.md", PARSED_HTML, updated_metadata), ("Root page without metadata", "root_without_metadata.md", PARSED_HTML, {}), - ("Page with metadata", "category/with_metadata.md", PARSED_HTML, PARSED_METADATA), + ("Page with metadata", "category/with_metadata.md", PARSED_HTML, updated_metadata), ("Page without metadata", "category/subcategory/without_metadata.md", PARSED_HTML, {}), ] diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py index 46a0f7da..81c4012b 100644 --- a/pydis_site/apps/content/tests/test_views.py +++ b/pydis_site/apps/content/tests/test_views.py @@ -90,6 +90,11 @@ class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): with self.assertRaises(Http404): self.ViewClass.get_template_names() + def test_get_template_names_returns_page_template_for_category_with_page(self): + """Make sure the proper page is returned for category locations with pages.""" + patch_dispatch_attributes(self.ViewClass, "tmp") + self.assertEqual(self.ViewClass.get_template_names(), ["content/page.html"]) + def test_get_context_data_with_valid_page(self): """The method should return required fields in the template context.""" request = self.factory.get("/root") @@ -145,6 +150,23 @@ class PageOrCategoryViewTests(MockPagesTestCase, SimpleTestCase, TestCase): with self.subTest(msg=msg): self.assertEqual(context[key], expected_value) + def test_get_context_data_for_category_with_page(self): + """Make sure the proper page is returned for category locations with pages.""" + request = self.factory.get("/category") + self.ViewClass.setup(request) + self.ViewClass.dispatch(request, location="tmp") + + context = self.ViewClass.get_context_data() + expected_page_context = { + "page": PARSED_HTML, + "page_title": PARSED_METADATA["title"], + "page_description": PARSED_METADATA["description"], + "relevant_links": PARSED_METADATA["relevant_links"] + } + for key, expected_value in expected_page_context.items(): + with self.subTest(): + self.assertEqual(context[key], expected_value) + def test_get_context_data_breadcrumbs(self): """The method should return correct breadcrumbs.""" request = self.factory.get("/category/subcategory/with_metadata") -- cgit v1.2.3 From 4208626262d6cf790da1c0e00765b375fa427aa7 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 1 Apr 2021 16:29:29 +0800 Subject: Place category pages in the same directory as categories. --- .../resources/guides/pydis-guides/how-to-contribute-a-page.md | 6 +++--- pydis_site/apps/content/tests/helpers.py | 4 ++-- pydis_site/apps/content/tests/test_views.py | 1 - pydis_site/apps/content/utils.py | 3 ++- pydis_site/apps/content/views/page_category.py | 11 ++++------- 5 files changed, 11 insertions(+), 14 deletions(-) (limited to 'pydis_site/apps/content/tests/helpers.py') diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/how-to-contribute-a-page.md b/pydis_site/apps/content/resources/guides/pydis-guides/how-to-contribute-a-page.md index c2d9d975..51f1097d 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/how-to-contribute-a-page.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/how-to-contribute-a-page.md @@ -36,14 +36,14 @@ icon: fas fa-folder # Optional All the markdown files in this folder will then be under this category. -#### Having the Category also be a Page -In order to make categories a page, place a page inside the category folder **with the same name as the category folder**. +#### Having the Category Also Be a Page +In order to make categories a page, just create a page **with the same name as the category folder** in the category's parent directory. ```plaintext guides +├── contributing.md ├── contributing │   ├── _info.yml -│   ├── contributing.md │   └── bot.md └── _info.yml ``` diff --git a/pydis_site/apps/content/tests/helpers.py b/pydis_site/apps/content/tests/helpers.py index 59cd3bd6..202dee42 100644 --- a/pydis_site/apps/content/tests/helpers.py +++ b/pydis_site/apps/content/tests/helpers.py @@ -50,9 +50,9 @@ class MockPagesTestCase(TestCase): ├── root.md ├── root_without_metadata.md ├── not_a_page.md + ├── tmp.md ├── tmp |   ├── _info.yml - |   ├── tmp.md |   └── category |    ├── _info.yml |      └── subcategory_without_info @@ -86,6 +86,6 @@ class MockPagesTestCase(TestCase): # for testing purposes. # 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/tmp.md", contents=MARKDOWN_WITH_METADATA) + 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_dir("tmp/category/subcategory_without_info") diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py index 81c4012b..ab266b29 100644 --- a/pydis_site/apps/content/tests/test_views.py +++ b/pydis_site/apps/content/tests/test_views.py @@ -29,7 +29,6 @@ def patch_dispatch_attributes(view: PageOrCategoryView, location: str) -> None: view.full_location = view.location # Possible places to find page content information - view.category_page_path = view.full_location.joinpath(view.location.stem).with_suffix(".md") view.category_path = view.full_location view.page_path = view.full_location.with_suffix(".md") diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py index d6886ce2..d3f270ff 100644 --- a/pydis_site/apps/content/utils.py +++ b/pydis_site/apps/content/utils.py @@ -32,7 +32,8 @@ def get_category_pages(path: Path) -> Dict[str, Dict]: pages = {} for item in path.glob("*.md"): - if item.is_file(): + # Only list page if there is no category with the same name + if item.is_file() and not item.with_suffix("").is_dir(): pages[item.stem] = frontmatter.load(item).metadata return pages diff --git a/pydis_site/apps/content/views/page_category.py b/pydis_site/apps/content/views/page_category.py index a995d2a1..8783e33f 100644 --- a/pydis_site/apps/content/views/page_category.py +++ b/pydis_site/apps/content/views/page_category.py @@ -19,7 +19,6 @@ class PageOrCategoryView(TemplateView): self.full_location = settings.PAGES_PATH / self.location # Possible places to find page content information - self.category_page_path = self.full_location.joinpath(self.location.stem).with_suffix(".md") self.category_path = self.full_location self.page_path = self.full_location.with_suffix(".md") @@ -27,7 +26,7 @@ class PageOrCategoryView(TemplateView): def get_template_names(self) -> t.List[str]: """Checks if the view uses the page template or listing template.""" - if self.category_page_path.is_file() or self.page_path.is_file(): + if self.page_path.is_file(): template_name = "content/page.html" elif self.category_path.is_dir(): template_name = "content/listing.html" @@ -40,13 +39,11 @@ class PageOrCategoryView(TemplateView): """Assign proper context variables based on what resource user requests.""" context = super().get_context_data(**kwargs) - if self.category_page_path.is_file(): - context.update(self._get_page_context(self.category_page_path)) + if self.page_path.is_file(): + context.update(self._get_page_context(self.page_path)) elif self.category_path.is_dir(): context.update(self._get_category_context(self.category_path)) context["path"] = f"{self.location}/" # Add trailing slash to simplify template - elif self.page_path.is_file(): - context.update(self._get_page_context(self.page_path)) else: raise Http404 @@ -71,7 +68,7 @@ class PageOrCategoryView(TemplateView): } @staticmethod - def _get_category_context(path) -> t.Dict[str, t.Any]: + def _get_category_context(path: Path) -> t.Dict[str, t.Any]: category = utils.get_category(path) return { "categories": utils.get_categories(path), -- cgit v1.2.3 From bb8a57a00835ffae8382f4360e0f55888bbe03b0 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Fri, 2 Apr 2021 17:47:42 +0800 Subject: Use metadata titles in Sub-Articles dropdown. This allows us to keep filenames (thus URLs) as concise as possible, while having a more descriptive entry in the Sub-Articles dropdown for category pages. --- pydis_site/apps/content/templatetags/__init__.py | 0 pydis_site/apps/content/templatetags/str_methods.py | 21 --------------------- pydis_site/apps/content/tests/helpers.py | 2 +- pydis_site/apps/content/tests/test_templatetags.py | 12 ------------ pydis_site/apps/content/tests/test_views.py | 2 +- pydis_site/apps/content/views/page_category.py | 15 +++++++++++---- pydis_site/templates/content/dropdown.html | 6 ++---- 7 files changed, 15 insertions(+), 43 deletions(-) delete mode 100644 pydis_site/apps/content/templatetags/__init__.py delete mode 100644 pydis_site/apps/content/templatetags/str_methods.py delete mode 100644 pydis_site/apps/content/tests/test_templatetags.py (limited to 'pydis_site/apps/content/tests/helpers.py') 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 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() - - -@register.filter(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 %} -