mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-04-10 04:57:44 +03:00
* feat: support reverse proxy path prefixes * fix: respect BASE_URL in SAML callback fallback * fix: make BASE_URL runtime configurable
41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
---
|
|
import { BASE_PATH_WINDOW_KEY } from '@/lib/base-path';
|
|
|
|
const normalizeBasePath = (value) => {
|
|
if (!value || !value.trim()) {
|
|
return '/';
|
|
}
|
|
|
|
let normalized = value.trim();
|
|
if (!normalized.startsWith('/')) {
|
|
normalized = `/${normalized}`;
|
|
}
|
|
|
|
normalized = normalized.replace(/\/+$/, '');
|
|
return normalized || '/';
|
|
};
|
|
|
|
const runtimeBasePath = normalizeBasePath(process.env.BASE_URL);
|
|
---
|
|
|
|
<script is:inline define:vars={{ BASE_PATH_WINDOW_KEY, runtimeBasePath }}>
|
|
window[BASE_PATH_WINDOW_KEY] = runtimeBasePath;
|
|
|
|
const getThemePreference = () => {
|
|
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
|
|
return localStorage.getItem('theme');
|
|
}
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
};
|
|
const isDark = getThemePreference() === 'dark';
|
|
document.documentElement.classList[isDark ? 'add' : 'remove']('dark');
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
const observer = new MutationObserver(() => {
|
|
const isDark = document.documentElement.classList.contains('dark');
|
|
localStorage.setItem('theme', isDark ? 'dark' : 'light');
|
|
});
|
|
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
}
|
|
</script>
|