Dark mode for Pygments

This commit is contained in:
Sumner Evans 2020-04-07 21:36:38 -06:00
parent 543ae58a37
commit 91aa9016e7
No known key found for this signature in database
GPG key ID: 8904527AB50022FD

View file

@ -20,7 +20,17 @@
if (theme === 'browser') { if (theme === 'browser') {
theme = darkSchemeWatch.matches ? 'dark' : 'light'; theme = darkSchemeWatch.matches ? 'dark' : 'light';
} }
const pygmentsTheme = theme === 'light'
? '{{ PYGMENTS_STYLE }}'
: '{{ PYGMENTS_STYLE_DARK or PYGMENTS_STYLE }}'
console.log(`Switching theme to ${theme}.`) console.log(`Switching theme to ${theme}.`)
Array.from(document.head.getElementsByTagName('link')).forEach(linkEl => {
if (linkEl.href.match(/\/theme\/pygments\/.*\.min\.css/)) {
linkEl.href = `/theme/pygments/${pygmentsTheme}.min.css`;
}
});
if (theme === 'dark') { if (theme === 'dark') {
document.body.classList.add('dark_theme'); document.body.classList.add('dark_theme');
document.body.classList.remove('light_theme'); document.body.classList.remove('light_theme');