Make navbar dynamic
This also adds some caching to them for performance reasons
This commit is contained in:
parent
db6ca1ae8d
commit
5fb0fcd629
6 changed files with 56 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
{% load static wagtailcore_tags wagtailuserbar %}
|
{% load static wagtailcore_tags wagtailuserbar navbar_tags footer_tags cache %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -23,13 +23,18 @@
|
||||||
<body class="{% block body_class %}{% endblock %}">
|
<body class="{% block body_class %}{% endblock %}">
|
||||||
{% wagtailuserbar %}
|
{% wagtailuserbar %}
|
||||||
|
|
||||||
{% include "navbar.html" %}
|
{% cache 3600 "navbar" page %}
|
||||||
|
{% navbar page %}
|
||||||
|
{% endcache %}
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
{% include "footer.html" %}
|
{% cache 3600 "footer" %}
|
||||||
|
{% footer %}
|
||||||
|
{% endcache %}
|
||||||
|
|
||||||
|
|
||||||
<script async defer type="text/javascript" src="{% static 'js/base.js' %}"></script>
|
<script async defer type="text/javascript" src="{% static 'js/base.js' %}"></script>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
{% load wagtailcore_tags %}
|
||||||
|
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="has-text-centered">
|
<div class="has-text-centered">
|
||||||
<p>
|
<p>
|
||||||
© <a href="/">TheOrangeOne</a> {% now "Y" %}
|
© <a href="{% pageurl homepage %}">TheOrangeOne</a> {% now "Y" %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="has-text-centered is-size-7" id="to-top">
|
<div class="has-text-centered is-size-7" id="to-top">
|
|
@ -1,7 +1,9 @@
|
||||||
<nav class="navbar has-background-black has-text-white is-family-code" role="navigation" aria-label="main navigation">
|
{% load wagtailcore_tags %}
|
||||||
|
|
||||||
|
<nav class="navbar has-background-black has-text-white" role="navigation" aria-label="main navigation">
|
||||||
<div class="navbar-brand">
|
<div class="navbar-brand">
|
||||||
<a class="navbar-item" href="/">
|
<a class="navbar-item has-text-white is-family-code" href="{% pageurl homepage %}">
|
||||||
<img src="">
|
/home/theorangeone
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a role="button" class="navbar-burger" id="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbar">
|
<a role="button" class="navbar-burger" id="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbar">
|
||||||
|
@ -11,11 +13,13 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="navbar" class="navbar-menu has-background-black">
|
<div id="navbar" class="navbar-menu has-background-black is-family-code">
|
||||||
<div class="navbar-start">
|
<div class="navbar-start">
|
||||||
<a class="navbar-item has-text-white">
|
{% for nav_page in nav_pages %}
|
||||||
Posts
|
<a class="navbar-item has-text-grey" href="{% pageurl nav_page %}">
|
||||||
</a>
|
~/{{ nav_page.slug }}
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="navbar-end is-hidden-touch mr-2">
|
<div class="navbar-end is-hidden-touch mr-2">
|
12
website/common/templatetags/footer_tags.py
Normal file
12
website/common/templatetags/footer_tags.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.template import Library
|
||||||
|
|
||||||
|
from website.home.models import HomePage
|
||||||
|
|
||||||
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag("common/footer.html")
|
||||||
|
def footer() -> dict:
|
||||||
|
return {
|
||||||
|
"homepage": HomePage.objects.live().get(),
|
||||||
|
}
|
19
website/common/templatetags/navbar_tags.py
Normal file
19
website/common/templatetags/navbar_tags.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from django.template import Library
|
||||||
|
from wagtail.models import Page
|
||||||
|
|
||||||
|
from website.home.models import HomePage
|
||||||
|
|
||||||
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag("common/navbar.html")
|
||||||
|
def navbar(current_page: Page) -> dict:
|
||||||
|
homepage = HomePage.objects.live().get()
|
||||||
|
return {
|
||||||
|
"current_page": current_page,
|
||||||
|
"homepage": homepage,
|
||||||
|
"nav_pages": homepage.get_children()
|
||||||
|
.live()
|
||||||
|
.filter(show_in_menus=True)
|
||||||
|
.order_by("title"),
|
||||||
|
}
|
|
@ -81,6 +81,9 @@ WSGI_APPLICATION = "website.wsgi.application"
|
||||||
|
|
||||||
DATABASES = {"default": env.db(default=f"sqlite:///{BASE_DIR}/db.sqlite3")}
|
DATABASES = {"default": env.db(default=f"sqlite:///{BASE_DIR}/db.sqlite3")}
|
||||||
|
|
||||||
|
CACHES = {"default": env.cache(default="dummycache://")}
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue