From baebc131ed3be8d015acaad589b697983435037e Mon Sep 17 00:00:00 2001 From: kosayoda Date: Wed, 24 Mar 2021 14:09:32 +0800 Subject: Refactor common HTML into a base template. --- pydis_site/apps/content/views/page_category.py | 7 ++- pydis_site/templates/content/base.html | 36 ++++++++++++ pydis_site/templates/content/listing.html | 76 ++++++++----------------- pydis_site/templates/content/page.html | 77 ++++++++------------------ 4 files changed, 88 insertions(+), 108 deletions(-) create mode 100644 pydis_site/templates/content/base.html (limited to 'pydis_site') diff --git a/pydis_site/apps/content/views/page_category.py b/pydis_site/apps/content/views/page_category.py index 7e8fe07d..623c2596 100644 --- a/pydis_site/apps/content/views/page_category.py +++ b/pydis_site/apps/content/views/page_category.py @@ -35,12 +35,17 @@ class PageOrCategoryView(TemplateView): if self.full_location.is_dir(): context["categories"] = utils.get_categories(self.full_location) - context["category_info"] = utils.get_category(self.full_location) + category = utils.get_category(self.full_location) + context["category_info"] = category + context["page_title"] = category["name"] + context["page_description"] = category["description"] context["content"] = utils.get_pages(self.full_location) context["path"] = f"{self.location}/" # Add trailing slash here to simplify template elif self.full_location.with_suffix(".md").is_file(): page_result = utils.get_page(self.full_location.with_suffix(".md")) context["page"] = page_result + context["page_title"] = page_result["metadata"]["title"] + context["page_description"] = page_result["metadata"]["description"] context["relevant_links"] = page_result["metadata"].get("relevant_links", {}) else: raise Http404 diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html new file mode 100644 index 00000000..1508dfb3 --- /dev/null +++ b/pydis_site/templates/content/base.html @@ -0,0 +1,36 @@ +{% extends 'base/base.html' %} +{% load static %} + +{% block title %}{{ page_title }}{% endblock %} +{% block head %} + + + + +{% endblock %} + +{% block content %} + {% include "base/navbar.html" %} + + + +
+
+
+

{{ page_title }}

+ {% block page_content %}{% endblock %} +
+
+
+{% endblock %} diff --git a/pydis_site/templates/content/listing.html b/pydis_site/templates/content/listing.html index 6c84a38c..9271f3ab 100644 --- a/pydis_site/templates/content/listing.html +++ b/pydis_site/templates/content/listing.html @@ -1,59 +1,27 @@ -{% extends 'base/base.html' %} -{% load static %} +{% extends 'content/base.html' %} -{% block title %}{{ category_info.name|default:"Pages" }}{% endblock %} -{% block head %} - - - - -{% endblock %} - -{% block content %} - {% include "base/navbar.html" %} +{% block page_content %} + {% for category, data in categories.items %} +
+ + + - - -
-
-
-

{{ category_info.name|default:"Pages" }}

- {% for category, data in categories.items %} -
- - - - - - - {{ data.name }} - -

{{ data.description }}

-
- {% endfor %} - {% for page, data in content.items %} -
- - - - - {{ data.title }} - -

{{ data.description }}

-
- {% endfor %} -
+ {% endfor %} + {% for page, data in content.items %} +
+ + + + + {{ data.title }} + +

{{ data.description }}

-
+ {% endfor %} {% endblock %} diff --git a/pydis_site/templates/content/page.html b/pydis_site/templates/content/page.html index c3b2285b..2b366e50 100644 --- a/pydis_site/templates/content/page.html +++ b/pydis_site/templates/content/page.html @@ -1,60 +1,31 @@ -{% extends 'base/base.html' %} -{% load static %} +{% extends 'content/base.html' %} -{% block title %}{{ page.metadata.title }}{% endblock %} {% block head %} - - - - - - - + {{ block.super }} + + + {% endblock %} -{% block content %} - {% include "base/navbar.html" %} - - - -
-
-
-

{{ page.metadata.title }}

- - {% if relevant_links|length > 0 %} -
-
- {{ page.page|safe }} -
-
-
- - -
-
-
- {% else %} -
{{ page.page|safe }}
- {% endif %} +{% block page_content %} + {% if relevant_links|length > 0 %} +
+
+ {{ page.page|safe }} +
+
+
+ + +
-
- + {% else %} +
{{ page.page|safe }}
+ {% endif %} {% endblock %} -- cgit v1.2.3