Skip to content

Commit 40ec7ba

Browse files
authored
dark mode (#57)
* chore(taskfile): improved task preview added node_modules/.bin folder to the path to force use the hugo version from npm. Added automatic opening of website in preview mode. Added the correct baseUrl to preview * feat: dark mode This change introduces the ability for the user to set the dark theme
1 parent e38f855 commit 40ec7ba

8 files changed

Lines changed: 143 additions & 15 deletions

File tree

Taskfile.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ tasks:
4444
- rm -rf openserverless-task
4545

4646
preview:
47+
silent: true
4748
desc: preview the websites
4849
cmds:
49-
- hugo server -O
50+
- PATH="node_modules/.bin:$PATH" hugo server --baseURL "http://localhost:1313/" -O
5051

5152
debug:
53+
silent: true
5254
desc: debug the websites
5355
cmds:
54-
- hugo server --ignoreCache --debug --disableFastRender
56+
- PATH="node_modules/.bin:$PATH" hugo server --ignoreCache --debug --disableFastRender

assets/scss/_styles_project.scss

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,67 @@
2626
url('/fonts/quattrocento-v23-latin-regular.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5+, IE 9+, Safari 3.1+, iOS 4.2+, Android Browser 2.2+ */
2727
}
2828

29+
:root {
30+
--primary-color: #0073e6;
31+
--background-light: #ffffff;
32+
--text-light: #333333;
33+
--border-light: #dddddd;
34+
--link-light: #0056b3;
35+
--code-bg-light: #f5f5f5;
36+
--bs-secondary-color: #333333;
37+
}
38+
39+
.dark-mode {
40+
--background-light: #121212;
41+
--text-light: #e0e0e0;
42+
--border-light: #444444;
43+
--link-light: #4a90e2;
44+
--code-bg-light: #1e1e1e;
45+
--bs-secondary-color: #e0e0e0;
46+
--td-pre-bg: #1e1e1e;
47+
}
48+
49+
body {
50+
background-color: var(--background-light);
51+
color: var(--text-light);
52+
transition: background-color 0.3s ease, color 0.3s ease;
53+
}
54+
55+
a {
56+
color: var(--link-light);
57+
transition: color 0.3s ease;
58+
}
59+
60+
a:hover {
61+
color: color-mix(in srgb, var(--link-light) 80%, white);
62+
}
63+
64+
header, footer {
65+
background-color: var(--background-light);
66+
border-bottom: 1px solid var(--border-light);
67+
}
68+
69+
pre, code {
70+
background-color: var(--code-bg-light);
71+
color: var(--text-light);
72+
border-radius: 5px;
73+
padding: 5px;
74+
}
75+
76+
button.toggle-dark-mode {
77+
background: var(--primary-color);
78+
color: #fff;
79+
border: none;
80+
padding: 8px 12px;
81+
border-radius: 5px;
82+
cursor: pointer;
83+
}
84+
85+
button.toggle-dark-mode:hover {
86+
background: color-mix(in srgb, var(--primary-color) 80%, black);
87+
}
88+
89+
2990
p { font-family: "Quattrocento" !important;}
3091

3192
.navbar, aside, .quote-title {
@@ -36,6 +97,8 @@ h1, h2, h3 ,h4, h5, .lead {
3697
font-family: "Baloo 2" !important;
3798
}
3899

100+
101+
39102
div.td-content h1,
40103
div.td-content h2,
41104
div.td-content h3,
@@ -45,7 +108,7 @@ div.td-content h6 {
45108
color: #265d85 !important;
46109
}
47110

48-
.td-sidebar-nav-active-item {
111+
.ttq,d-sidebar-nav-active-item {
49112
color: #ff0000;
50113
}
51114

@@ -57,6 +120,7 @@ aside{
57120
.text-default { color: black; }
58121
.text-white { color: white; }
59122

123+
60124
.center-image-container {
61125
text-align: center;
62126
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
$font-family-base: "Quattrocento";
22
$td-enable-google-fonts: false;
33

4-
$primary: #265d85 !default;
4+
$primary: #265d85 !default;
5+

hugo.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ params:
193193
# add "hide_readingtime: true" to the page's front matter
194194
readingtime:
195195
enable: false
196+
197+
showLightDarkModeMenu: true
196198

197199
links:
198200
# End user relevant links. These will show up on left side of footer and in the community page if you have one.

layouts/partials/footer.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@
5050
</div>
5151
</div>
5252
</footer>
53+
{{ if .Site.Params.ui.showLightDarkModeMenu -}}
54+
{{ partial "theme-toggler" . }}
55+
{{ end -}}

layouts/partials/head.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<script>
2+
// Applica immediatamente la modalità scura se salvata in localStorage
3+
(function() {
4+
const currentTheme = localStorage.getItem('theme');
5+
if (currentTheme === 'dark') {
6+
document.documentElement.classList.add('dark-mode');
7+
}
8+
})();
9+
</script>
110
<meta charset="utf-8">
211
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
312
{{ range .AlternativeOutputFormats -}}

layouts/partials/navbar.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,7 @@
7171
{{ partial "navbar-lang-selector.html" . -}}
7272
</li>
7373
{{ end -}}
74-
{{ if .Site.Params.ui.showLightDarkModeMenu -}}
75-
<li class="td-light-dark-menu nav-item dropdown">
76-
{{ partial "theme-toggler" . }}
77-
</li>
78-
{{ end -}}
7974
</ul>
80-
81-
82-
</div>
83-
<div class="d-none d-lg-block">
84-
{{ partial "search-input.html" . }}
85-
</div>
75+
</div>
8676
</div>
8777
</nav>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<div id="theme-toggler-container">
2+
<button id="theme-toggler" class="btn btn-light-dark" aria-label="Toggle theme">
3+
<span id="theme-icon" class="fa fa-sun"></span>
4+
</button>
5+
</div>
6+
7+
<script>
8+
// Gestione della modalità scura
9+
const themeToggler = document.getElementById('theme-toggler');
10+
const themeIcon = document.getElementById('theme-icon');
11+
const currentTheme = localStorage.getItem('theme') || 'light';
12+
13+
// Cambia tema al clic
14+
themeToggler.addEventListener('click', () => {
15+
document.body.classList.toggle('dark-mode');
16+
const isDarkMode = document.body.classList.contains('dark-mode');
17+
localStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
18+
themeIcon.classList.toggle('fa-sun', !isDarkMode);
19+
themeIcon.classList.toggle('fa-moon', isDarkMode);
20+
21+
});
22+
</script>
23+
24+
<style>
25+
/* Stili per il pulsante flottante */
26+
#theme-toggler-container {
27+
position: fixed;
28+
bottom: 20px;
29+
right: 20px;
30+
z-index: 1000;
31+
}
32+
33+
.btn-light-dark {
34+
background: #ffffff;
35+
border: 1px solid #ddd;
36+
border-radius: 50%;
37+
width: 50px;
38+
height: 50px;
39+
display: flex;
40+
align-items: center;
41+
justify-content: center;
42+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
43+
cursor: pointer;
44+
transition: background-color 0.3s, transform 0.2s;
45+
}
46+
47+
.btn-light-dark:hover {
48+
background: #f0f0f0;
49+
transform: scale(1.1);
50+
}
51+
52+
.dark-mode .btn-light-dark {
53+
background: #333333;
54+
color: #ffffff;
55+
border-color: #444444;
56+
}
57+
</style>

0 commit comments

Comments
 (0)