dark mode

This commit is contained in:
cupcakearmy 2021-12-23 00:24:26 +01:00
parent c9dc5fadd1
commit 1a3c78d4bf
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
2 changed files with 22 additions and 4 deletions

View File

@ -15,9 +15,19 @@
--clr-primary: hsl(219, 90%, 80%);
--clr-secondary: hsl(64, 93%, 51%);
--clr-error: hsl(0, 73.9%, 65.5%);
--clr-transparent-0: hsla(0, 0%, 0%, 0.1);
--animation: all 250ms ease;
}
@media (prefers-color-scheme: dark) {
:root {
--clr-light: #010101;
--clr-dark: #ffffff;
--clr-primary: hsl(219, 90%, 30%);
--clr-transparent-0: hsla(0, 0%, 100%, 0.1);
}
}
body {
margin: 0;
overflow: hidden;

View File

@ -1,5 +1,4 @@
<script lang="ts">
import 'highlight.js/styles/github.css'
import hljs from 'highlight.js/lib/core'
import javascript from 'highlight.js/lib/languages/javascript'
import python from 'highlight.js/lib/languages/python'
@ -32,9 +31,10 @@
.replace(' ', '-')
}
onMount(() => {
onMount(async () => {
hljs.highlightAll()
// Add anchor links to headers
const selector = [1, 2, 3, 4, 5, 6].map((i) => `div.adapter h${i}`).join(', ')
const elements = window.document.querySelectorAll(selector)
elements.forEach((el) => {
@ -43,6 +43,14 @@
el.innerHTML = `<a class="target-link" name="${hash}" href="${window.location.pathname}#${hash}">${el.innerHTML}</a>`
}
})
async function update(isDark: boolean) {
isDark ? await import('highlight.js/styles/github-dark.css') : await import('highlight.js/styles/github.css')
}
const match = window.matchMedia('(prefers-color-scheme: dark)')
match.addEventListener('change', (e) => update(e.matches))
update(match.matches)
})
</script>
@ -89,12 +97,12 @@
div :global(pre) {
padding: 1em;
background: #0000000d;
background: var(--clr-transparent-0);
overflow: auto;
}
div :global(code) {
background: #00000012;
background: var(--clr-transparent-0);
padding: 0.25em;
font-size: 0.8em;
}