aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content
diff options
context:
space:
mode:
authorGravatar kosayoda <[email protected]>2021-04-01 16:29:29 +0800
committerGravatar kosayoda <[email protected]>2021-04-01 18:04:14 +0800
commit4208626262d6cf790da1c0e00765b375fa427aa7 (patch)
tree84ccbe32dbeef7cb48c620c36b3c461605df6382 /pydis_site/apps/content
parentAdd new tests to achieve full coverage. (diff)
Place category pages in the same directory as categories.
Diffstat (limited to 'pydis_site/apps/content')
-rw-r--r--pydis_site/apps/content/resources/guides/pydis-guides/how-to-contribute-a-page.md6
-rw-r--r--pydis_site/apps/content/tests/helpers.py4
-rw-r--r--pydis_site/apps/content/tests/test_views.py1
-rw-r--r--pydis_site/apps/content/utils.py3
-rw-r--r--pydis_site/apps/content/views/page_category.py11
5 files changed, 11 insertions, 14 deletions
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),