aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content/urls.py
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2022-01-21 21:55:19 +0000
committerGravatar GitHub <[email protected]>2022-01-21 21:55:19 +0000
commit721d313e9170661bd969fe8e737866b2560dae4a (patch)
tree44aa19b25573ada3bf2ef3cf16c9c279d7b05603 /pydis_site/apps/content/urls.py
parentImplement voice mute + migration from voice mute -> voice ban (diff)
parentMerge pull request #640 from Krish-bhardwaj/main (diff)
Merge branch 'main' into voicemute
Diffstat (limited to 'pydis_site/apps/content/urls.py')
-rw-r--r--pydis_site/apps/content/urls.py43
1 files changed, 40 insertions, 3 deletions
diff --git a/pydis_site/apps/content/urls.py b/pydis_site/apps/content/urls.py
index c11b222a..fe7c2852 100644
--- a/pydis_site/apps/content/urls.py
+++ b/pydis_site/apps/content/urls.py
@@ -1,9 +1,46 @@
-from django.urls import path
+import typing
+from pathlib import Path
+
+from django_distill import distill_path
from . import views
app_name = "content"
+
+
+def __get_all_files(root: Path, folder: typing.Optional[Path] = None) -> list[str]:
+ """Find all folders and markdown files recursively starting from `root`."""
+ if not folder:
+ folder = root
+
+ results = []
+
+ for item in folder.iterdir():
+ name = item.relative_to(root).__str__().replace("\\", "/")
+
+ if item.is_dir():
+ results.append(name)
+ results.extend(__get_all_files(root, item))
+ else:
+ path, extension = name.rsplit(".", maxsplit=1)
+ if extension == "md":
+ results.append(path)
+
+ return results
+
+
+def get_all_pages() -> typing.Iterator[dict[str, str]]:
+ """Yield a dict of all pag categories."""
+ for location in __get_all_files(Path("pydis_site", "apps", "content", "resources")):
+ yield {"location": location}
+
+
urlpatterns = [
- path("", views.PageOrCategoryView.as_view(), name='pages'),
- path("<path:location>/", views.PageOrCategoryView.as_view(), name='page_category'),
+ distill_path("", views.PageOrCategoryView.as_view(), name='pages'),
+ distill_path(
+ "<path:location>/",
+ views.PageOrCategoryView.as_view(),
+ name='page_category',
+ distill_func=get_all_pages
+ ),
]