diff options
author | 2021-04-02 17:47:42 +0800 | |
---|---|---|
committer | 2021-04-02 17:47:42 +0800 | |
commit | bb8a57a00835ffae8382f4360e0f55888bbe03b0 (patch) | |
tree | ba1817a540189d098ce856aa876167640a714b13 /pydis_site/apps/content/views | |
parent | Fix overriden PAGES_PATH in settings.py. (diff) |
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.
Diffstat (limited to 'pydis_site/apps/content/views')
-rw-r--r-- | pydis_site/apps/content/views/page_category.py | 15 |
1 files changed, 11 insertions, 4 deletions
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"] = [ { |