add night mode toggle and autoformat css

This commit is contained in:
Tom 2024-07-29 10:24:59 +01:00
parent 9c056ab755
commit a4f1d84723
15 changed files with 692 additions and 491 deletions

View File

@ -8,6 +8,7 @@ A list of things to check once in a while to make sure I haven't broken them ina
- Mobile and web layouts looks ok.
- Dark mode and light mode both look ok.
- OG tags render nicely, use https://www.opengraph.xyz/
- Check the rss feed https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fthomashodson.com%2Ffeed.xml
## Todo
- change the OG image used for the landing page so it's not just my face.

View File

@ -17,6 +17,13 @@
</p>
{% include sidebar.html%}
<div class="user-toggle">
<div role="status" class="visually-hidden js-mode-status"></div>
<button class="toggle-button js-mode-toggle">
<span class="toggle-button__icon" aria-hidden="true"></span>
</button>
</div>
{{ include.extra }}
<hr>
</header>

View File

@ -1,5 +1,5 @@
<!doctype html>
<html>
<html class = "no-js">
<head>
{% include default_head_tags.html%}
</head>

View File

@ -1,5 +1,5 @@
<!doctype html>
<html>
<html class = "no-js">
<head>
{% include default_head_tags.html%}

View File

@ -1,7 +1,7 @@
$font_stack: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
$title_font_stack: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", "sans serif", HelveticaNeue-CondensedBlack;
$horizontal_breakpoint: 700px;
$horizontal_breakpoint: 900px;
$vertical_breakpoint: 500px;
// For the images on the blogroll, projects and highlights pages

View File

@ -11,6 +11,7 @@
@import "comments"; //the mastodon comments
@import "model_viewer"; //Styles for the 3D model viewer
@import "mastodon_timeline";
@import "night_mode_toggle";
// The syntax highlighting css
// generated with rougify style bw > code_style_bw.scss
@ -19,32 +20,60 @@
@import "d2";
* {
box-sizing: border-box;
font-family: $font_stack;
text-rendering: geometricPrecision;
}
:root {
--theme-text-color: #222;
--theme-bg-color: #fcfcfc;
--theme-model-line-color: #222;
--theme-model-bg-color: #fcfcfc;
--theme-subtle-outline: oklch(90% 0 50);
--theme-highlight-color: hsl(338, 75%, 60%);
--theme-highlight-color-transparent: hsla(338, 75%, 60%, 33%);
// constrain width and center
--body-max-width: 900px;
--body-width: min(100vw, 900px);
--body-margin: calc((100vw - var(--body-width)) / 2);
--color-mode: "light";
--color-dark: #141414;
--color-dark-alpha: rgba(0, 0, 0, 0.1);
--color-light: #efefef;
--color-light-alpha: rgba(255, 255, 255, 0.9);
--icon-sun: url('data:image/svg+xml,\
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">\
<path d="M18 12c0-0.811-0.161-1.587-0.455-2.295-0.304-0.735-0.75-1.395-1.303-1.948-0.552-0.552-1.213-0.998-1.948-1.303-0.707-0.293-1.483-0.454-2.294-0.454s-1.587 0.161-2.295 0.455c-0.735 0.304-1.395 0.75-1.948 1.302s-0.998 1.213-1.302 1.948c-0.294 0.708-0.455 1.484-0.455 2.295s0.161 1.587 0.455 2.295c0.304 0.735 0.75 1.395 1.303 1.948 0.552 0.552 1.213 0.998 1.948 1.303 0.707 0.293 1.483 0.454 2.294 0.454s1.587-0.161 2.295-0.455c0.735-0.304 1.395-0.75 1.948-1.303s0.998-1.213 1.303-1.948c0.293-0.707 0.454-1.483 0.454-2.294zM16 12c0 0.544-0.108 1.060-0.303 1.529-0.202 0.489-0.5 0.929-0.869 1.299s-0.81 0.667-1.299 0.869c-0.469 0.195-0.985 0.303-1.529 0.303s-1.060-0.108-1.529-0.303c-0.489-0.202-0.929-0.5-1.299-0.869s-0.667-0.81-0.869-1.299c-0.195-0.469-0.303-0.985-0.303-1.529s0.108-1.060 0.303-1.529c0.202-0.489 0.5-0.929 0.869-1.299s0.81-0.667 1.299-0.869c0.469-0.195 0.985-0.303 1.529-0.303s1.060 0.108 1.529 0.303c0.489 0.202 0.929 0.5 1.299 0.869s0.667 0.81 0.869 1.299c0.195 0.469 0.303 0.985 0.303 1.529zM11 1v2c0 0.552 0.448 1 1 1s1-0.448 1-1v-2c0-0.552-0.448-1-1-1s-1 0.448-1 1zM11 21v2c0 0.552 0.448 1 1 1s1-0.448 1-1v-2c0-0.552-0.448-1-1-1s-1 0.448-1 1zM3.513 4.927l1.42 1.42c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-1.42-1.42c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414zM17.653 19.067l1.42 1.42c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-1.42-1.42c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414zM1 13h2c0.552 0 1-0.448 1-1s-0.448-1-1-1h-2c-0.552 0-1 0.448-1 1s0.448 1 1 1zM21 13h2c0.552 0 1-0.448 1-1s-0.448-1-1-1h-2c-0.552 0-1 0.448-1 1s0.448 1 1 1zM4.927 20.487l1.42-1.42c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-1.42 1.42c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0zM19.067 6.347l1.42-1.42c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-1.42 1.42c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0z"></path>\
</svg>');
--icon-sun-filter: invert(0.75);
--icon-moon: url('data:image/svg+xml,\
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">\
<path d="M21.996 12.882c0.022-0.233-0.038-0.476-0.188-0.681-0.325-0.446-0.951-0.544-1.397-0.219-0.95 0.693-2.059 1.086-3.188 1.162-0.696 0.047-1.399-0.027-2.077-0.226-0.656-0.192-1.29-0.501-1.874-0.932-0.655-0.484-1.181-1.074-1.575-1.729-0.409-0.68-0.676-1.432-0.792-2.206s-0.082-1.571 0.11-2.342c0.184-0.741 0.514-1.46 0.999-2.115 0.142-0.191 0.216-0.435 0.191-0.691-0.053-0.55-0.542-0.952-1.092-0.898-1.117 0.109-2.186 0.399-3.172 0.843-1.005 0.452-1.925 1.065-2.723 1.808-0.883 0.82-1.618 1.801-2.159 2.901-0.523 1.064-0.863 2.238-0.978 3.485-0.125 1.347 0.024 2.658 0.402 3.878 0.392 1.266 1.031 2.431 1.863 3.433s1.86 1.843 3.033 2.461c1.13 0.595 2.392 0.982 3.739 1.106s2.659-0.025 3.878-0.403c1.266-0.392 2.431-1.031 3.433-1.863s1.843-1.86 2.461-3.033c0.595-1.13 0.982-2.392 1.106-3.739zM19.567 14.674c-0.126 0.351-0.276 0.689-0.447 1.014-0.493 0.937-1.166 1.76-1.969 2.427s-1.735 1.178-2.747 1.491c-0.973 0.302-2.021 0.421-3.102 0.321s-2.089-0.41-2.99-0.884c-0.937-0.493-1.76-1.166-2.427-1.969s-1.178-1.735-1.491-2.747c-0.302-0.973-0.421-2.021-0.321-3.102 0.092-1 0.365-1.938 0.782-2.786 0.43-0.878 1.018-1.661 1.725-2.319 0.64-0.595 1.377-1.086 2.183-1.449 0.179-0.081 0.362-0.155 0.548-0.223-0.092 0.257-0.171 0.516-0.236 0.778-0.256 1.029-0.302 2.091-0.147 3.121s0.51 2.032 1.056 2.941c0.527 0.875 1.23 1.663 2.1 2.306 0.775 0.573 1.622 0.986 2.5 1.243 0.907 0.266 1.846 0.364 2.772 0.302 0.752-0.050 1.496-0.207 2.21-0.465z"></path>\
</svg>');
--icon-moon-filter: invert(0);
--background: #efefef;
--text-color: #141414;
--button-icon: var(--icon-moon);
--button-icon-filter: var(--icon-moon-filter);
--button-background: var(--color-dark);
--button-color: var(--color-light);
--border-color: var(--color-dark-alpha);
}
html {
width: 100vw;
scroll-behavior: smooth;
}
body {
--theme-text-color: #222;
--theme-bg-color: #fcfcfc;
--theme-model-line-color: #222;
--theme-model-bg-color: #fcfcfc;
--theme-subtle-outline: oklch(90% 0.0 50);
--theme-highlight-color: hsl(338, 75%, 60%);
--theme-highlight-color-transparent: hsla(338, 75%, 60%, 33%);
background: var(--theme-bg-color);
color: var(--theme-text-color);
// constrain width and center
max-width: 900px;
max-width: var(--body-max-width);
margin: auto;
}
@ -52,10 +81,15 @@ body {
main {
container: main / inline-size;
max-width: 560px;
margin-left: 240px;
padding-left: 30px;
padding-right: 30px;
--main-margin-left: 240px;
--main-padding-left: 30px;
--main-padding-right: 30px;
--main-max-width: 560px;
max-width: var(--main-max-width);
margin-left: var(--main-margin-left);
padding-left: var(--main-padding-left);
padding-right: var(--main-padding-right);
padding-top: 10vh;
min-height: 100vh;
@ -84,7 +118,8 @@ main {
text-wrap: balance;
}
p, figcaption {
p,
figcaption {
font-size: 1em;
line-height: 1.3em;
}
@ -100,7 +135,8 @@ a {
color: var(--theme-text-color);
}
header a, nav a {
header a,
nav a {
text-decoration: none;
color: var(--theme-text-color);
}
@ -130,7 +166,9 @@ figure {
}
}
figure > img, figure > svg, figure > canvas {
figure > img,
figure > svg,
figure > canvas {
width: 100%;
margin-bottom: 1em;
border-radius: 10px;
@ -150,7 +188,6 @@ section.image-grid-4x4 {
margin-bottom: 1em;
place-items: stretch stretch;
* {
margin: 0;
padding: 0;
@ -160,8 +197,12 @@ section.image-grid-4x4 {
}
section.note {
a {color: purple;}
p {margin: 0;}
a {
color: purple;
}
p {
margin: 0;
}
padding: 1em;
margin-top: 1em;
margin-bottom: 1em;
@ -175,7 +216,27 @@ section.center {
justify-content: center;
margin-top: 1em;
margin-bottom: 1em;
}
div.CodeRay,
.wide-outside-parent {
// width: 100vw;
position: relative;
width: calc(
100vw - var(--body-margin) - var(--main-margin-left) -
var(--main-padding-left) - var(--main-padding-right)
);
pre {
white-space: pre-wrap;
}
.line-numbers {
// display: none;
margin-right: 1em;
opacity: 0.3;
a {
text-decoration: none;
}
}
}
// If the browser doesn't support web components, hide anything with has-wc class
@ -187,48 +248,94 @@ body:not(.has-wc) .has-wc {
display: none;
}
@media
only screen and (max-width: $horizontal_breakpoint),
only screen and (max-height: $vertical_breakpoint)
{
@media only screen and (max-width: $horizontal_breakpoint),
only screen and (max-height: $vertical_breakpoint) {
main {
--main-margin-left: 0px;
--main-padding-left: 20px;
--main-padding-right: 20px;
padding-top: 10px;
padding-left: 20px;
padding-right: 20px;
margin: auto;
justify-content: flex-start;
}
article {
margin-left: 0px; }
margin-left: 0px;
}
h1 {font-size: 1.5em !important;}
h1 {
font-size: 1.5em !important;
}
.MathJax {
font-size: 0.8em !important;
overflow-x: auto;
overflow-y: hidden;
}
// Make code a bit smaller so it doesn't wrap as much
div.CodeRay {
font-size: 0.8rem;
}
}
// For the 3D model viewer
model-viewer {
width: 100%;
height: 300px;
.visually-hidden {
display: block;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px);
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(1px);
white-space: nowrap;
position: absolute;
}
// Add transitions for things that will be affected by night mode
body {
transition: background 500ms ease-in-out, color 200ms ease-in-out;
}
img {
transition: opacity 500ms ease-in-out;
}
svg.invertable,
img.invertable {
transition: filter 500ms ease-in-out;
}
@mixin night-mode {
--background: var(--color-dark);
--text-color: var(--color-light);
--button-icon: var(--icon-sun);
--button-icon-filter: var(--icon-sun-filter);
--button-background: var(--color-light);
--button-color: var(--color-dark);
--border-color: var(--color-light-alpha);
@media (prefers-color-scheme: dark) {
body {
--theme-text-color: #fcfcfc;
--theme-bg-color: #222;
--theme-subtle-outline: oklch(50% 0.0 50);
--theme-subtle-outline: oklch(50% 0 50);
}
img {
opacity: .75;
transition: opacity .5s ease-in-out;
img:not(.invertable) {
opacity: 0.75;
}
svg.invertable, img.invertable{
svg.invertable,
img.invertable {
opacity: 1;
filter: invert(1);
}
}
@media (prefers-color-scheme: dark) {
:root {
--color-mode: "dark";
}
:root:not([data-user-color-scheme]) {
@include night-mode;
}
}
[data-user-color-scheme="dark"] {
@include night-mode;
}

View File

@ -16,13 +16,22 @@ article.draft {
opacity: 0.5;
}
section.highlights {
margin-bottom: 2rem;
h1 {
margin-bottom: 1rem;
}
}
a.highlights-more {
margin-left: $left_pad;
}
main > h2 {
h1.highlights {
font-size: 1.75rem;
margin-left: $left_pad
margin-left: $left_pad;
margin-bottom: 1em;
}
article.blogroll {
@ -65,5 +74,8 @@ article.blogroll {
font-size: 1.2em;
}
}
a.highlights-more {
font-size: 1.25rem;
}
}

View File

@ -19,25 +19,31 @@ details[open] > summary:before {
//A little animation for the details opening
details[open] summary ~ * {
animation: sweep .5s ease-in-out;
animation: sweep 0.5s ease-in-out;
}
@keyframes sweep {
0% {opacity: 0; transform: translateX(-10px)}
100% {opacity: 1; transform: translateX(0)}
0% {
opacity: 0;
transform: translateX(-10px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
summary.cv:before {
content: '';
border-width: .4rem;
content: "";
border-width: 0.4rem;
border-style: solid;
border-color: transparent transparent transparent black;
border-color: transparent transparent transparent var(--theme-text-color);
position: absolute;
top: 0.2rem;
left: 1rem;
transform: rotate(0);
transform-origin: .2rem 50%;
transition: .25s transform ease;
transform-origin: 0.2rem 50%;
transition: 0.25s transform ease;
}
summary li {
@ -89,7 +95,9 @@ div.cv-title-container {
margin-bottom: 1em;
margin-top: 1em;
}
div.cv-title-container h2 {margin:0px;}
div.cv-title-container h2 {
margin: 0px;
}
div.cv-title-container a {
cursor: pointer;
@ -119,5 +127,4 @@ div.cv-title-container button:hover {
summary.cv {
flex-direction: column;
}
}

View File

@ -33,7 +33,7 @@ header {
max-width: 175px;
border-radius: 50%;
padding: 5px;
border: 1px solid #f2f3f3;
border: 1px solid var(--theme-text-color);
}
h1 {
@ -41,7 +41,8 @@ header {
font-size: 2em;
}
h1, h2 {
h1,
h2 {
font-family: $title_font_stack;
}
@ -68,10 +69,8 @@ header {
}
}
@media
only screen and (max-width: $horizontal_breakpoint),
only screen and (max-height: $vertical_breakpoint)
{
@media only screen and (max-width: $horizontal_breakpoint),
only screen and (max-height: $vertical_breakpoint) {
header {
position: relative;
width: 100%;
@ -91,10 +90,10 @@ header {
display: inline;
}
span:after {
content: ', ';
content: ", ";
}
span:last-of-type:after {
content: '';
content: "";
}
}
@ -128,7 +127,6 @@ header {
margin-left: 0;
}
}
}
nav {

View File

@ -81,4 +81,8 @@ outline-model-viewer {
transition: transform 0.3s, opacity 0.3s;
}
// For the 3D model viewer
model-viewer {
width: 100%;
height: 300px;
}

View File

@ -4,28 +4,21 @@ nav {
}
.current {
color: darkslategray;
color: var(--theme-highlight-color);
}
@media (prefers-color-scheme: dark) {
.current {
color: lightslategray;
}
}
@media
only screen and (max-width: $horizontal_breakpoint),
only screen and (max-height: $vertical_breakpoint)
{
@media only screen and (max-width: $horizontal_breakpoint),
only screen and (max-height: $vertical_breakpoint) {
nav.page-table-of-contents {
white-space: normal;
justify-content: left;
text-align: left;
ul {padding-left: 0em;}
ul {
padding-left: 0em;
}
li li {
padding-right: 0em;
padding-left: 2em;
}
}
}

View File

@ -0,0 +1,31 @@
.no-js .user-toggle {
display: none;
}
.user-toggle {
padding-top: 0.5rem;
}
.toggle-button {
width: 1.5rem;
height: 1.5rem;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 50%;
color: var(--theme-text-color);
background: var(--theme-background-color);
border: 1.5px solid var(--theme-text-color);
transition: background 500ms ease-in-out, color 200ms ease;
}
.toggle-button__icon {
background: var(--button-icon);
width: 0.9rem;
height: 0.9rem;
flex-shrink: 0;
margin: 0;
transform: translateY(0px); /* Optical adjustment */
transition: filter 200ms ease-in-out;
filter: var(--button-icon-filter);
}

View File

@ -5,7 +5,9 @@ article.project {
flex-wrap: nowrap;
flex-direction: row;
h2 {margin-top: 0;}
h2 {
margin-top: 0;
}
a.photo {
width: $thumbnail_image_size;
@ -23,26 +25,3 @@ article.project {
justify-content: center;
}
}
// @media
// only screen and (max-width: $horizontal_breakpoint),
// only screen and (max-height: $vertical_breakpoint)
// {
// main {
// padding-top: 10px;
// padding-left: 20px;
// padding-right: 20px;
// margin: 0px;
// }
// article {
// margin-left: 0px;
// }
// h1 {font-size: 1.5em !important;}
// .MathJax {
// font-size: 0.8em !important;
// overflow-x: auto;
// overflow-y: hidden;
// }
// }

View File

@ -3,16 +3,77 @@ function toggle_summary_by_class(element, topic) {
if (element.textContent === "Expand all") {
element.textContent = "Collapse all";
details.forEach(e => e.open = true);
details.forEach((e) => (e.open = true));
} else {
element.textContent = "Expand all"
details.forEach(e => e.open = false);
element.textContent = "Expand all";
details.forEach((e) => (e.open = false));
}
}
}
// Signal that we have JS enabled
document.documentElement.classList.remove("no-js");
// This signals to css that we have support for web components
// Allows us to set elements to act as fallbacks when js/web components are disabled.
if (window.customElements) {
document.querySelector('body').classList.add('has-wc');
document.querySelector("body").classList.add("has-wc");
}
// run the night mode toggle
const STORAGE_KEY = "user-color-scheme";
const COLOR_MODE_KEY = "--color-mode";
const modeToggleButton = document.querySelector(".js-mode-toggle");
const modeStatusElement = document.querySelector(".js-mode-status");
const getCSSCustomProp = (propKey) => {
let response = getComputedStyle(document.documentElement).getPropertyValue(
propKey
);
if (response.length) {
response = response.replace(/\"/g, "").trim();
}
return response;
};
const applySetting = (passedSetting) => {
let currentSetting = passedSetting || localStorage.getItem(STORAGE_KEY);
if (currentSetting) {
document.documentElement.setAttribute(
"data-user-color-scheme",
currentSetting
);
}
};
const toggleSetting = () => {
let currentSetting = localStorage.getItem(STORAGE_KEY);
switch (currentSetting) {
case null:
currentSetting =
getCSSCustomProp(COLOR_MODE_KEY) === "dark" ? "light" : "dark";
break;
case "light":
currentSetting = "dark";
break;
case "dark":
currentSetting = "light";
break;
}
localStorage.setItem(STORAGE_KEY, currentSetting);
return currentSetting;
};
modeToggleButton.addEventListener("click", (evt) => {
evt.preventDefault();
applySetting(toggleSetting());
});
applySetting();

1
ruff.toml Normal file
View File

@ -0,0 +1 @@
line-length = 60