diff --git a/django/src/pages/views.py b/django/src/pages/views.py index e6ef2764..e38e8b6d 100644 --- a/django/src/pages/views.py +++ b/django/src/pages/views.py @@ -19,11 +19,11 @@ def create_response( @require_GET def index(request): - return create_response(request, 'index.html') + return create_response(request, 'index.html', title="Home") @require_GET def games(request): - return create_response(request, 'games.html') + return create_response(request, 'games.html', title='Games') @require_GET def login(request: HttpRequest): @@ -39,4 +39,4 @@ def register(request: HttpRequest): @require_GET def error_404(request): - return create_response(request, '404.html') + return create_response(request, '404.html', title="Page not found") diff --git a/nginx/src/js/router.js b/nginx/src/js/router.js index 0c220f5e..78a0b328 100644 --- a/nginx/src/js/router.js +++ b/nginx/src/js/router.js @@ -23,6 +23,9 @@ async function fetchPage(pageName) { console.error(`Failed to fetch ${pageName}: ${data.error}`); return null; } + + document.title = ('title' in data) ? data.title : "Missing title"; + return data.html; } @@ -42,16 +45,6 @@ function loadScripts() { }); } -function updateTitle(pageName) { - const titles = { - "index": "Home", - "games": "Games", - "404": "Page Not Found" - }; - const title = titles[pageName] || "Page Not Found"; - document.title = title; -} - function updateActiveRoute(path) { const activeRoute = document.querySelector(`a[href="${path}"]`); if (activeRoute) { @@ -69,7 +62,6 @@ async function handleLocation() { document.getElementById("content").innerHTML = html; loadScripts(); - updateTitle(pageName); updateActiveRoute(path); }