fix: embed js into page so tera can preprocess

This commit is contained in:
zaaarf 2023-12-22 01:07:32 +01:00
parent 59d2191eda
commit a67109db24
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
2 changed files with 23 additions and 22 deletions

View file

@ -1,21 +0,0 @@
const setTheme = (theme) => {
document.documentElement.className = theme;
localStorage.setItem('theme', theme);
}
const hasCodeRun = localStorage.getItem('hasCodeRun');
if (!hasCodeRun) {
const defaultTheme = "{{ config.extra.default_theme }}";
setTheme(defaultTheme);
localStorage.setItem('hasCodeRun', 'true');
}
const getTheme = () => {
const theme = localStorage.getItem('theme');
if (theme) {
setTheme(theme);
}
}
getTheme();

View file

@ -92,5 +92,27 @@
{% block css %} {% block css %}
<link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/> <link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/>
{% endblock css %} {% endblock css %}
<script src="{{ get_url(path='js/script.js', trailing_slash=false) | safe }}" defer></script> <script>
const setTheme = (theme) => {
document.documentElement.className = theme;
localStorage.setItem('theme', theme);
}
const hasCodeRun = localStorage.getItem('hasCodeRun');
if (!hasCodeRun) {
const defaultTheme = "{{ config.extra.default_theme }}";
setTheme(defaultTheme);
localStorage.setItem('hasCodeRun', 'true');
}
const getTheme = () => {
const theme = localStorage.getItem('theme');
if (theme) {
setTheme(theme);
}
}
getTheme();
</script>