Chore/theme setup env config (#1181)

* chore: fix /assets/env-config.js 404 by moving it to public dir

* chore: set dark theme class before app load
This commit is contained in:
Bartłomiej Głownia 2022-09-02 12:27:28 +02:00 committed by GitHub
parent 02897f1ee1
commit bab1bac2dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -15,6 +15,7 @@
<ul>
<li><a href="./fonts.css">AlphaLyrae font</a></li>
<li><a href="./favicon.ico">Favicon</a></li>
<li><a href="./theme.js">Theme</a></li>
</ul>
</body>
</html>

9
apps/static/src/theme.js Normal file
View File

@ -0,0 +1,9 @@
(function () {
var storedTheme = window.localStorage.getItem('theme');
if (
storedTheme === 'dark' ||
(!storedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
document.documentElement.classList.add('dark');
}
})();

View File

@ -17,6 +17,11 @@ export default function Document() {
href="https://static.vega.xyz/favicon.ico"
/>
<link rel="stylesheet" href="https://static.vega.xyz/fonts.css" />
<script
src="https://static.vega.xyz/theme.js"
type="text/javascript"
async
/>
{['1', 'true'].includes(process.env['NX_USE_ENV_OVERRIDES'] || '') ? (
/* eslint-disable-next-line @next/next/no-sync-scripts */
<script src="/assets/env-config.js" type="text/javascript" />