Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update theme toggle icon on page load #25

Merged
merged 3 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ function toggleTheme(theme) {
themeToggle.innerHTML = theme == "dark" ? themeToggle.dataset.sunIcon : themeToggle.dataset.moonIcon;
toggleGiscusTheme(theme);
}
if (localStorage.getItem("theme") == "dark") toggleTheme("dark");

function updateThemeToggleIcon() {
const theme = localStorage.getItem("theme") || (preferDark.matches ? "dark" : "light");
themeToggle.innerHTML = theme == "dark" ? themeToggle.dataset.sunIcon : themeToggle.dataset.moonIcon;
}
window.onload = updateThemeToggleIcon();
mrtnvgr marked this conversation as resolved.
Show resolved Hide resolved

function toggleGiscusTheme(theme) {
const iframe = document.querySelector('iframe.giscus-frame');
Expand Down
3 changes: 1 addition & 2 deletions templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
</head>

<body class="{% block page %}{% endblock page%}">
<script>if (localStorage.getItem('theme') == 'dark') document.body.classList.add('dark');</script>
mrtnvgr marked this conversation as resolved.
Show resolved Hide resolved
{% block content %}{% endblock content %}
{% block script %}{% endblock script %}
<script src="/js/main.js"></script>
</body>

</html>
</html>