]> git.danielmrcl.dev Git - danielmrcl.dev.git/commitdiff
switch light/dark theme automatically as change browser preference
authorDaniel Jr <dan@danielmrcl.dev>
Mon, 6 Oct 2025 18:54:36 +0000 (15:54 -0300)
committerDaniel Jr <dan@danielmrcl.dev>
Mon, 6 Oct 2025 18:54:36 +0000 (15:54 -0300)
Signed-off-by: Daniel Jr <dan@danielmrcl.dev>
assets/scss/partial/_theme.scss [new file with mode: 0644]
assets/scss/style.scss
hugo.toml
layouts/index.html
layouts/partials/head.html

diff --git a/assets/scss/partial/_theme.scss b/assets/scss/partial/_theme.scss
new file mode 100644 (file)
index 0000000..60d3a07
--- /dev/null
@@ -0,0 +1,224 @@
+// global-reset()
+
+*,
+*:before,
+*:after {
+  box-sizing: border-box;
+}
+html {
+  margin: 0;
+  padding: 0;
+  height: 100%;
+  border-top: 2px solid $color-text;
+  -webkit-text-size-adjust: 100%;
+  -ms-text-size-adjust: 100%;
+}
+body {
+  margin: 0;
+  height: 100%;
+  background-color: $color-background;
+  color: $color-text;
+  font-display: swap;
+  font-weight: 400;
+  font-size: $font-size;
+  font-family: $font-family-body;
+  line-height: $line-height;
+  text-rendering: geometricPrecision;
+  flex: 1;
+
+  @include antialias();
+
+  @extend $base-style !optional;
+}
+.content {
+  position: relative;
+  display: flex;
+  flex-direction: column;
+  min-height: 100%;
+  overflow-wrap: break-word;
+
+  p {
+    @include hyphens(auto);
+  }
+  code {
+    @include hyphens(manual);
+  }
+  a {
+    color: $color-text;
+    text-decoration: none;
+
+    @include underline(5px, $color-text);
+
+    &:hover {
+      background-image: linear-gradient(transparent, transparent 4px, $color-link 4px, $color-link);
+    }
+  }
+  a.icon {
+    background: none;
+
+    &:hover {
+      color: $color-link;
+    }
+  }
+  h1 a,
+  .h1 a,
+  h2 a,
+  h3 a,
+  h4 a,
+  h5 a,
+  h6 a {
+    background: none;
+    color: inherit;
+    text-decoration: none;
+  }
+  h1 a:hover,
+  .h1 a:hover,
+  h2 a:hover,
+  h3 a:hover,
+  h4 a:hover,
+  h5 a:hover,
+  h6 a:hover {
+    @include underline(6px, $color-link);
+  }
+  h6 {
+    a {
+      background: none;
+      color: inherit;
+      text-decoration: none;
+    }
+  }
+  h6 {
+    a:hover {
+      @include underline(6px, $color-link);
+    }
+  }
+}
+@media (min-width: 540px) {
+  .image-wrap {
+    flex-direction: row;
+    margin-bottom: 2rem;
+
+    .image-block {
+      flex: 1 0 35%;
+      margin-right: 2rem;
+    }
+    p {
+      flex: 1 0 65%;
+    }
+  }
+}
+.max-width {
+  max-width: $page-width;
+}
+@media (max-width: 480px) {  // smaller margins at smaller screen widths
+  .px3 {
+    padding-right: 1rem;
+    padding-left: 1rem;
+  }
+  .my4 {
+    margin-top: 2rem;
+    margin-bottom: 2rem;
+  }
+}
+
+@media (min-width: 480px) {
+  p {
+    text-align: justify;
+  }
+}
+
+@import "header";
+@import "post/actions_desktop";
+@import "post/actions_mobile";
+@import "index";
+@import "article";
+@import "archive";
+@import "comments";
+@import "footer";
+@import "pagination";
+@import "search";
+@import "tags";
+@import "tooltip";
+@import "categories";
+
+pre {
+  overflow-x: auto;
+  padding: 15px 15px 10px 15px;
+  border: 1px dotted $color-border;
+  border-radius: 2px;
+  -webkit-border-radius: 2px;
+  font-size: 13px;
+  font-family: $font-family-mono;
+  line-height: 22px;
+  position: relative;
+
+  .code-copy-btn {
+    position: absolute;
+    top: 0;
+    right: 0;
+    border: 0;
+    border-radius: 0 2px;
+    padding: 0;
+    font-family: "JetBrains Mono", monospace;
+    font-weight: 800;
+    font-size: 0.9em;
+    line-height: 1.7;
+    color: #fff;
+    background-color: #8c8c8c;
+    min-width: 60px;
+    text-align: center;
+    cursor: pointer;
+    letter-spacing: 0em;
+  }
+
+  .code-copy-btn:hover {
+    background-color: #666;
+    color: #2bbc8a;
+  }
+
+  code {
+    display: block;
+    padding: 0;
+    border: none;
+  }
+}
+
+code {
+  font-family: $font-family-mono;
+  padding: 0 5px;
+  border: 1px dotted $color-border;
+  border-radius: 2px;
+  -webkit-border-radius: 2px;
+}
+
+.highlight {
+
+  & > div {
+    border-radius: 2px;
+    -webkit-border-radius: 2px;
+  }
+
+  pre {
+    border: none;
+    background: none;
+  }
+
+  table {
+
+    pre {
+      margin-top: 0;
+    }
+
+    td:first-child {
+      pre {
+        padding-right: 0;
+      }
+    }
+
+    td:last-child {
+      pre {
+        padding-left: 0;
+      }
+    }
+  }
+}
index f8215d46c1131eef481a96d23e4310de86ece9d8..0243f580a3724f8198307f3c35025a41e59c067d 100644 (file)
 @import "variables";
-@import "colors/{{ site.Params.colortheme | default "white" }}";
 @import "util";
 @import "mixins";
-@import "extend";
 @import "fonts";
 
-// global-reset()
-
-*,
-*:before,
-*:after {
-  box-sizing: border-box;
-}
-html {
-  margin: 0;
-  padding: 0;
-  height: 100%;
-  border-top: 2px solid $color-text;
-  -webkit-text-size-adjust: 100%;
-  -ms-text-size-adjust: 100%;
-}
-body {
-  margin: 0;
-  height: 100%;
-  background-color: $color-background;
-  color: $color-text;
-  font-display: swap;
-  font-weight: 400;
-  font-size: $font-size;
-  font-family: $font-family-body;
-  line-height: $line-height;
-  text-rendering: geometricPrecision;
-  flex: 1;
-
-  @include antialias();
-
-  @extend $base-style !optional;
+@media (prefers-color-scheme: light) {
+  @import "colors/white";
+  @import "extend";
+  @import "partial/theme";
 }
-.content {
-  position: relative;
-  display: flex;
-  flex-direction: column;
-  min-height: 100%;
-  overflow-wrap: break-word;
-
-  p {
-    @include hyphens(auto);
-  }
-  code {
-    @include hyphens(manual);
-  }
-  a {
-    color: $color-text;
-    text-decoration: none;
-
-    @include underline(5px, $color-text);
-
-    &:hover {
-      background-image: linear-gradient(transparent, transparent 4px, $color-link 4px, $color-link);
-    }
-  }
-  a.icon {
-    background: none;
 
-    &:hover {
-      color: $color-link;
-    }
-  }
-  h1 a,
-  .h1 a,
-  h2 a,
-  h3 a,
-  h4 a,
-  h5 a,
-  h6 a {
-    background: none;
-    color: inherit;
-    text-decoration: none;
-  }
-  h1 a:hover,
-  .h1 a:hover,
-  h2 a:hover,
-  h3 a:hover,
-  h4 a:hover,
-  h5 a:hover,
-  h6 a:hover {
-    @include underline(6px, $color-link);
-  }
-  h6 {
-    a {
-      background: none;
-      color: inherit;
-      text-decoration: none;
-    }
-  }
-  h6 {
-    a:hover {
-      @include underline(6px, $color-link);
-    }
-  }
+@media (prefers-color-scheme: dark) {
+  @import "colors/dark";
+  @import "extend";
+  @import "partial/theme";
 }
-@media (min-width: 540px) {
-  .image-wrap {
-    flex-direction: row;
-    margin-bottom: 2rem;
-
-    .image-block {
-      flex: 1 0 35%;
-      margin-right: 2rem;
-    }
-    p {
-      flex: 1 0 65%;
-    }
-  }
-}
-.max-width {
-  max-width: $page-width;
-}
-@media (max-width: 480px) {  // smaller margins at smaller screen widths
-  .px3 {
-    padding-right: 1rem;
-    padding-left: 1rem;
-  }
-  .my4 {
-    margin-top: 2rem;
-    margin-bottom: 2rem;
-  }
-}
-
-@media (min-width: 480px) {
-  p {
-    text-align: justify;
-  }
-}
-
-@import "partial/header";
-@import "partial/post/actions_desktop";
-@import "partial/post/actions_mobile";
-@import "partial/index";
-@import "partial/article";
-@import "partial/archive";
-@import "partial/comments";
-@import "partial/footer";
-@import "partial/pagination";
-@import "partial/search";
-@import "partial/tags";
-@import "partial/tooltip";
-@import "partial/categories";
-
-pre {
-  overflow-x: auto;
-  padding: 15px 15px 10px 15px;
-  border: 1px dotted $color-border;
-  border-radius: 2px;
-  -webkit-border-radius: 2px;
-  font-size: 13px;
-  font-family: $font-family-mono;
-  line-height: 22px;
-  position: relative;
-
-  .code-copy-btn {
-    position: absolute;
-    top: 0;
-    right: 0;
-    border: 0;
-    border-radius: 0 2px;
-    padding: 0;
-    font-family: "JetBrains Mono", monospace;
-    font-weight: 800;
-    font-size: 0.9em;
-    line-height: 1.7;
-    color: #fff;
-    background-color: #8c8c8c;
-    min-width: 60px;
-    text-align: center;
-    cursor: pointer;
-    letter-spacing: 0em;
-  }
-
-  .code-copy-btn:hover {
-    background-color: #666;
-    color: #2bbc8a;
-  }
-
-  code {
-    display: block;
-    padding: 0;
-    border: none;
-  }
-}
-
-code {
-  font-family: $font-family-mono;
-  padding: 0 5px;
-  border: 1px dotted $color-border;
-  border-radius: 2px;
-  -webkit-border-radius: 2px;
-}
-
-.highlight {
-
-  & > div {
-    border-radius: 2px;
-    -webkit-border-radius: 2px;
-  }
-
-  pre {
-    border: none;
-    background: none;
-  }
-
-  table {
-
-    pre {
-      margin-top: 0;
-    }
-
-    td:first-child {
-      pre {
-        padding-right: 0;
-      }
-    }
-
-    td:last-child {
-      pre {
-        padding-left: 0;
-      }
-    }
-  }
-}
\ No newline at end of file
index 32646a185d4fcf58d062594070c962fd7e711764..11ba01b5e6e411b649d88f962487b6c2e8c16c4f 100644 (file)
--- a/hugo.toml
+++ b/hugo.toml
@@ -25,7 +25,6 @@ style = "gruvbox"
 tabWidth = 4
 
 [params]
-colortheme = "dark"
 rss = false
 tocInline = true
 description = "Since 2021 I have been developing web services in microservice architecture for critical, efficient, and scalable systems. I also love Linux, cloud, cli-tools, hardware, and all about computers."
index ccb16d56886946d856f7861387efd6670c2ae5d2..d19121accc7cc0d6934b919064fb1aa3363b49f4 100644 (file)
@@ -44,7 +44,7 @@
         <li class="project-item">
                        <a href="{{ .url }}">{{ .name }}</a>: {{ .desc | markdownify }}
                        {{ range .tags }}
-                       <span style="font-size: 10px; color: {{ .color }}; font-weight: bold; background-color: #282828;">{{ .name }}</span>
+                       <span style="font-size: 10px; color: {{ .color }}; font-weight: bold;">{{ .name }}</span>
                        {{ end }}
         </li>
         {{ end }}
@@ -57,7 +57,7 @@
         <li class="career-item">
                        <a href="{{ .url }}">{{ .name }}</a>: {{ .desc | markdownify }}
                        {{ range .tags }}
-                       <span style="font-size: 10px; color: {{ .color }}; font-weight: bold; background-color: #282828;">{{ .name }}</span>
+                       <span style="font-size: 10px; color: {{ .color }}; font-weight: bold;">{{ .name }}</span>
                        {{ end }}
         </li>
         {{ end }}
index b46ee84e874ea6bd5772ffb1dcfb2542309c12fc..ef615b6de8f9f76cb16e219814e1c7aada838ced 100644 (file)
   <meta name="googlebot" content="index,follow,snippet,archive">
   {{ template "_internal/opengraph.html" . }}
   {{ template "_internal/twitter_cards.html" . }}
-  {{ .Scratch.Set "colortheme" "white"}}
-  {{ if .Site.Params.Colortheme }}
-    {{ .Scratch.Set "colortheme" .Site.Params.Colortheme }}
-  {{ end }}
-  {{ $colortheme := .Scratch.Get "colortheme" }}
 
   {{- $options := (dict "targetPath" "css/styles.css" "outputStyle" "compressed" "enableSourceMap" "true") -}}
   {{- $styles := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "scss/style.scss" . | resources.ToCSS $options | resources.Fingerprint "sha512" }}