Skip to content

Commit c07dc13

Browse files
author
cakePhone
committed
fix theme switching
1 parent 63b1a3f commit c07dc13

6 files changed

Lines changed: 12 additions & 6 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
(function() {
3+
var theme = localStorage.getItem('theme');
4+
if (theme) {
5+
document.documentElement.classList.add('theme-' + theme);
6+
}
7+
})();
8+
</script>

_includes/layouts/post_layout.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
{% include 'components/theme-init.liquid' %}
67
<title>{{ title }}</title>
78
<link rel="icon" href="/assets/img/favicon.svg" type="image/x-icon">
89
<link href="/assets/css/global.css" rel="stylesheet">

assets/js/theme.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ document.addEventListener('DOMContentLoaded', () => {
88

99
if (!ambientSky) return;
1010

11-
// Check for saved theme preference or use system preference
12-
const savedTheme = localStorage.getItem('theme');
13-
if (savedTheme) {
14-
document.documentElement.classList.add(`theme-${savedTheme}`);
15-
}
16-
1711
ambientSky.addEventListener('click', () => {
1812
const html = document.documentElement;
1913
const isDark = html.classList.contains('theme-dark') ||

blog/index.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ eleventyImport:
99
<head>
1010
<meta charset="UTF-8">
1111
<meta name="viewport" content="width=device-width, initial-scale=1">
12+
{% include 'components/theme-init.liquid' %}
1213
<title>Miguel's Blog</title>
1314

1415
<link rel="icon" href="/assets/img/favicon.svg" type="image/x-icon">

index.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
{% include 'components/theme-init.liquid' %}
78

89
<title>Miguel's Portfolio</title>
910

projects/index.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ eleventyImport:
77
<head>
88
<meta charset="UTF-8">
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
{% include 'components/theme-init.liquid' %}
1011
<title>Miguel's Projects</title>
1112
<link rel="stylesheet" href="/assets/css/global.css">
1213
<link rel="stylesheet" href="/assets/css/general-read.css">

0 commit comments

Comments
 (0)