No more redirect loop - middleware just sets cookie on response, frontend uses history.replaceState to remove ?lang=XX from URL.
55 lines
2.2 KiB
Django/Jinja
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>
|