Skip to content

Commit 34825f6

Browse files
committed
Add dark mode with toggler switch in nav.
Default mode is either system preference if supported, or light mode if not. Highlight.js removed from config.toml as it did not seem to be in use. The "monokai" theme for codeblocks has been changed to "pygments" theme to support dark/light mode switching. It's not amazing on dark mode but it's better than eye strain.
1 parent cb4cea2 commit 34825f6

File tree

5 files changed

+118
-7
lines changed

5 files changed

+118
-7
lines changed

config.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ publishDir = "../website"
5151
date_format = "Mon, Jan 2, 2006"
5252
description = "A Rosetta Stone for Software Metadata"
5353

54-
# options for highlight.js (version, additional languages, and theme)
55-
highlightjsVersion = "9.10.0"
56-
highlightCDN = "//cdn.bootcss.com"
57-
highlightjsLang = ["r", "yaml", "json"]
58-
highlightjsTheme = "github"
59-
6054
[params.logo]
6155
url = "logo.png"
6256
width = 50
@@ -67,3 +61,5 @@ publishDir = "../website"
6761
[markup.goldmark]
6862
[markup.goldmark.renderer]
6963
unsafe = true
64+
[markup.highlight]
65+
style = 'pygments'

themes/CodeMeta-Pyramids/layouts/partials/head.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
<link rel="stylesheet" type="text/css"
1616
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
1717
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" />
18+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
1819
<!-- CSS Files -->
1920
<link href="/css/core/bootstrap.css" rel="stylesheet" />
20-
<link href="/css/codemeta.css" rel="stylesheet" />
2121
<link href="/css/material-kit.css?v=2.0.4" rel="stylesheet" />
22+
<link href="/css/codemeta.css" rel="stylesheet" />
2223

2324
<!-- Additional icons: fa-docker, academicons, R-logo -->
2425
<link rel="stylesheet" href="https://cdn.rawgit.com/gaborcsardi/r-font/master/rlogo.css">

themes/CodeMeta-Pyramids/layouts/partials/nav.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
title = "{{ .Name }}">{{ .Pre }} {{ .Name }}</a>
2121
</li>
2222
{{ end }}
23+
<li>
24+
<div class="form-check dark-light-toggler">
25+
<input class="form-check-input" type="checkbox" id="darkModeSwitch">
26+
<label class="form-check-label" for="darkModeSwitch">
27+
<i role="presentation" class='bi bi-sun-fill d-none' id='light-mode-bi' title="Light mode"></i>
28+
<i role="presentation" class='bi bi-moon-stars-fill' id='dark-mode-bi' title="Dark mode"></i>
29+
</label>
30+
</div>
31+
</li>
2332
</ul>
2433
</div>
2534
</div>

themes/CodeMeta-Pyramids/static/css/codemeta.css

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
77
*/
88

9+
/*!
10+
* dark mode support for unstyled elements
11+
*/
12+
13+
:root {
14+
color-scheme: light dark;
15+
}
16+
917
/*!
1018
* Make the header colour change on-scroll smoother
1119
*/
20+
1221
#sectionsNav {
1322
transition: all 0.25s;
1423
}
@@ -20,3 +29,66 @@
2029
.navbar {
2130
--bs-navbar-toggler-focus-width: none;
2231
}
32+
33+
/*!
34+
* Dark mode toggler button
35+
*/
36+
37+
li.dark-light-toggler {
38+
height: 50px;
39+
}
40+
41+
.dark-light-toggler .form-check-label {
42+
padding: 0px;
43+
margin-top: 10px;
44+
margin-left: 25px;
45+
font-size: 1.25em;
46+
}
47+
48+
/*!
49+
* These are the base colours which are using the Bootstrap
50+
* variables which will work with dark/light mode switching
51+
*
52+
* The definitions here are overriding material-kit.css
53+
*/
54+
55+
body {
56+
color: var(--bs-body-color);
57+
background-color: var(--bs-body-bg);
58+
}
59+
60+
.main{
61+
background-color: var(--bs-secondary-bg);
62+
}
63+
64+
[data-bs-theme=light] div.highlight {
65+
border: 1px solid var(--bs-dark-border-subtle);
66+
padding: 10px 10px 0px 10px;
67+
}
68+
69+
[data-bs-theme=dark] div.highlight {
70+
border: 1px solid var(--bs-body-bg);
71+
padding: 10px 10px 0px 10px;
72+
}
73+
74+
.navbar {
75+
background-color: var(--bs-body-bg) !important;
76+
}
77+
78+
[data-bs-theme=dark] .highlight {
79+
background-color: var(--bs-border-color) !important;
80+
}
81+
82+
[data-bs-theme=dark] .navbar {
83+
color: var(--bs-body-color) !important;
84+
}
85+
86+
@media only screen and (max-width: 992px) {
87+
.navbar-collapse, .navbar-collapse::after {
88+
background-color: var(--bs-body-bg) !important;
89+
}
90+
.nav-open .nav-item a{
91+
color: var(--bs-body-color) !important;
92+
}
93+
}
94+

themes/CodeMeta-Pyramids/static/js/codemeta.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
*/
88

9+
// Navbar transparency at top of scroll
10+
911
const headerEl = document.querySelector('#sectionsNav');
1012

1113
function manageNav() {
@@ -23,3 +25,34 @@ if (performance.navigation.type == performance.navigation.TYPE_RELOAD) {
2325
window.addEventListener('scroll', () => {
2426
manageNav();
2527
});
28+
29+
// Darkmode toggler
30+
document.addEventListener('DOMContentLoaded', (event) => {
31+
const htmlEl = document.documentElement;
32+
const switchEl = document.getElementById('darkModeSwitch');
33+
const darkEl = document.getElementById('dark-mode-bi');
34+
const lightEl = document.getElementById('light-mode-bi');
35+
36+
// Set the default theme to light if no setting is found in local storage
37+
const currentTheme = localStorage.getItem('bsTheme') || 'light';
38+
htmlEl.setAttribute('data-bs-theme', currentTheme);
39+
switchEl.checked = currentTheme === 'light';
40+
41+
switchEl.addEventListener('change', function () {
42+
if (this.checked) {
43+
htmlEl.setAttribute('data-bs-theme', 'light');
44+
localStorage.setItem('bsTheme', 'light');
45+
if (darkEl.classList.contains('d-none')) {
46+
lightEl.classList.add('d-none');
47+
darkEl.classList.remove('d-none');
48+
}
49+
} else {
50+
htmlEl.setAttribute('data-bs-theme', 'dark');
51+
localStorage.setItem('bsTheme', 'dark');
52+
if (lightEl.classList.contains('d-none')) {
53+
darkEl.classList.add('d-none');
54+
lightEl.classList.remove('d-none');
55+
}
56+
}
57+
});
58+
});

0 commit comments

Comments
 (0)