pig.py/templates/base.html.j2
Russell Ballestrini 4b247f0be9 Fix lang param: middleware sets cookie, frontend cleans URL
No more redirect loop - middleware just sets cookie on response,
frontend uses history.replaceState to remove ?lang=XX from URL.
2026-01-05 22:17:13 -05:00

55 lines
2.2 KiB
Django/Jinja

<!---------------------------------------------------------------------------
|
| Welcome, curious one. You found the source.
|
| This is Adventure #1. Not all side quests are called out.
|
| The source code for neopig is Public Domain. Steal what works for you.
|
| If you seek Adventure #2, consider: what happens at /fnord ?
|
| - The Sign Maker
|
---------------------------------------------------------------------------->
<!DOCTYPE html>
<html lang="{{ lang }}">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}neopig{% endblock %}</title>
<link rel="stylesheet" href="/static/css/discordia.css">
<style>{% block extra_css %}{% endblock %}</style>
{% block extra_head %}{% endblock %}
</head>
<body>
<div class="nav">
<a href="/" class="brand">neopig</a>
<a href="/">{{ t.search }}</a>
<a href="/live">{{ t.live }}</a>
<a href="/random">{{ t.random }}</a>
<a href="/crawl">{{ t.crawl }}</a>
{% if import_mode %}<a href="/import">{{ t.import_nav }}</a>{% endif %}
<a href="/about">{{ t.about }}</a>
<select id="lang-select" onchange="setLang(this.value)" style="background:#1a1a1a;color:#888;border:1px solid #333;border-radius:4px;padding:4px 8px;font-size:12px;cursor:pointer;">
{% for code, name in langs.items() %}<option value="{{ code }}"{% if code == lang %} selected{% endif %}>{{ name }}</option>{% endfor %}
</select>
</div>
<script>
function setLang(code) {
localStorage.setItem('neopig_lang', code);
document.cookie = 'lang=' + code + ';path=/;max-age=31536000';
if (window.UNCLOSEAI_LANGUAGE !== undefined) window.UNCLOSEAI_LANGUAGE = code;
location.reload();
}
// Clean ?lang=XX from URL (cookie already set by middleware)
(function() {
const url = new URL(location.href);
if (url.searchParams.has('lang')) {
url.searchParams.delete('lang');
history.replaceState(null, '', url.pathname + url.search + url.hash);
}
})();
</script>
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
</body>
</html>