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/views/page_category.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'pydis_site/apps/content/views') 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"] = [ { -- cgit v1.2.3