diff options
author | 2021-05-19 09:02:21 +0200 | |
---|---|---|
committer | 2021-05-19 09:02:21 +0200 | |
commit | 5c37aee79c04d9199dc47b9d60f9899a0f6571d9 (patch) | |
tree | 9041c01dc0124fe96be467de7bb994daa372efd3 /pydis_site/apps/resources/utils.py | |
parent | Add bulma-modal, we'll need it later. (diff) |
Dramatically simplify resources.
We don't need _category_info, we don't need subcategories, we this will
be much simpler now.
Also, rglob is nice.
Diffstat (limited to 'pydis_site/apps/resources/utils.py')
-rw-r--r-- | pydis_site/apps/resources/utils.py | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/pydis_site/apps/resources/utils.py b/pydis_site/apps/resources/utils.py index 1855fc80..6e21e2ba 100644 --- a/pydis_site/apps/resources/utils.py +++ b/pydis_site/apps/resources/utils.py @@ -2,41 +2,16 @@ import typing as t from pathlib import Path import yaml +from django.conf import settings +RESOURCES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "resources", "resources") -def get_resources(path: Path) -> t.List[t.Dict]: + +def get_resources() -> t.List[t.Dict]: """Loads resource YAMLs from provided path.""" resources = [] - for item in path.iterdir(): - if item.is_file() and item.suffix == ".yaml" and item.name != "_category_info.yaml": - resources.append(yaml.safe_load(item.read_text())) + for item in RESOURCES_PATH.rglob("*.yaml"): + resources.append(yaml.safe_load(item.read_text())) return resources - - -def get_subcategories(path: Path) -> t.List[t.Dict]: - """Loads resources subcategories with their resources by provided path.""" - subcategories = [] - - for item in path.iterdir(): - if item.is_dir() and item.joinpath("_category_info.yaml").exists(): - subcategories.append({ - "category_info": { - **yaml.safe_load( - item.joinpath("_category_info.yaml").read_text() - ), - "raw_name": item.name - }, - "resources": [ - yaml.safe_load(subitem.read_text()) - for subitem in item.iterdir() - if ( - subitem.is_file() - and subitem.suffix == ".yaml" - and subitem.name != "_category_info.yaml" - ) - ] - }) - - return subcategories |