Skip to content

Commit a6dbcd3

Browse files
committed
dark mode
1 parent 31c9626 commit a6dbcd3

File tree

6 files changed

+284
-160
lines changed

6 files changed

+284
-160
lines changed

_static/smileiLogo_tutorials.svg

Lines changed: 0 additions & 5 deletions
Loading

_static/smileiLogo_tutorials_large.svg

Lines changed: 0 additions & 5 deletions
Loading

conf.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
# General information about the project.
5454
project = u'Smilei tutorials'
55-
copyright = u'2019'
55+
copyright = u'2025'
5656
author = u''
5757

5858
# The version info for the project you're documenting, acts as replacement for
@@ -62,20 +62,14 @@
6262
# The short X.Y version.
6363

6464

65-
def get_version():
66-
"""
67-
Returns project version as string from 'git describe' command.
68-
"""
69-
from subprocess import Popen, PIPE
70-
pipe = Popen('git describe --tags --always', stdout=PIPE, shell=True)
71-
72-
return str(pipe.stdout.read() or 'X.Y')
73-
74-
version = get_version()
65+
from subprocess import check_output
66+
try:
67+
version = check_output('git describe --tags --abbrev=0', shell=True).decode().strip('v\n')
68+
except :
69+
version = " unknown"
7570

7671
# The full version, including alpha/beta/rc tags.
77-
release = version.rstrip()
78-
version = release.lstrip('v')
72+
release = version
7973

8074
# The language for content autogenerated by Sphinx. Refer to documentation
8175
# for a list of supported languages.
@@ -325,4 +319,6 @@ def get_version():
325319
:class: green
326320
.. role:: orange
327321
:class: orange
322+
.. role:: grey
323+
:class: grey
328324
"""

smilei_theme/layout.html

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
{%- set this_menu = sections[1].split("%") %}
1717
{%- set this_menu_url = this_menu[0] | trim | safe %}
1818
{%- set this_menu_name = this_menu[1] | trim | safe %}
19+
{%- if this_menu_name != "Index" %}
1920
{%- set this_menu = [this_menu_url, this_menu_name] %}
2021
{%- for section in sections[2:] %}
2122
{%- set this_section = section.split("%")%}
@@ -28,6 +29,7 @@
2829
{%- endfor %}
2930
{%- set _ = menus.append(this_menu) %}
3031
{%- endif %}
32+
{%- endif %}
3133
{%- endfor %}
3234
{%- set last_menu = menus[-1][1] %}
3335

@@ -61,9 +63,9 @@
6163
{%- set url = section[0] %}
6264
{%- set entry = section[1] %}
6365
{%- if entry == title %}
64-
</ul>
66+
</ul>
6567
{{ toc }}
66-
<ul>
68+
<ul id="smallScreenMenuAfterTOC">
6769
{%- else %}
6870
<li class="outer">
6971
<a href="{{ url }}">{{ entry }}</a>
@@ -95,7 +97,7 @@
9597
<div class="header">
9698
<div class="logo">
9799
<a href="{{ pathto(master_doc) }}">
98-
<img class="logo" src="{{ pathto('_static/' ~ logo, 1) }}" alt="Logo" />
100+
<img class="logo" src="{{ pathto('_static/smileiLogo_tutorials.svg', 1) }}" alt="Logo" />
99101
</a>
100102
</div>
101103

@@ -160,16 +162,15 @@
160162
<g transform="translate(0,-932.36216)" >
161163
<circle
162164
r="25" cy="977.51044" cx="38.078663"
163-
style="opacity:1;fill:none;stroke:#ffffff;stroke-width:10;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
165+
style="opacity:1;fill:none;stroke:#ffffff;stroke:var(--header_text);stroke-width:10;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
164166
<rect
165167
transform="matrix(0.36717877,0.93015039,-0.93427297,0.35655858,0,0)"
166-
rx="4.9996676" ry="7.4995141"
167-
y="316.16959" x="947.6142"
168+
rx="4.9996676" ry="7.4995141" x="947.6142" y="316.16959"
168169
height="14.117695" width="46.476151"
169-
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;" />
170+
style="opacity:1;fill:#ffffff;fill:var(--header_text);fill-opacity:1;stroke:none;" />
170171
<path
171172
d="m 41.383282,962.25996 a 15,15 0 0 1 11.660107,11.6355"
172-
style="opacity:1;fill:none;stroke:#ffffff;stroke-width:3;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
173+
style="opacity:1;fill:none;stroke:#ffffff;stroke:var(--header_text);stroke-width:3;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
173174
</g>
174175
</svg>
175176
</div>
@@ -178,21 +179,18 @@
178179
xmlns="http://www.w3.org/2000/svg"
179180
viewBox="0 0 80 120">
180181
<g
181-
transform="translate(0,-932.36216)">
182-
<path
183-
d="m 10,962.36216 60,60.00004"
184-
style="fill:none;stroke:#ffffff;stroke-width:10;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" />
185-
<path
186-
d="M 70,962.36216 10,1022.3622"
187-
style="fill:none;stroke:#ffffff;stroke-width:10;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" />
182+
transform="translate(0,-932.36216)"
183+
style="fill:none;stroke:#ffffff;stroke:var(--header_text);stroke-width:10;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none">
184+
<path d="m 10,962.36216 60,60.00004" />
185+
<path d="M 70,962.36216 10,1022.3622" />
188186
</g>
189187
</svg>
190188
</div>
191189

192-
<div id="smallScreenMenuButton" onclick="toggleSmallScreenMenu(event)">
190+
<div id="smallScreenMenuButton" onclick="event.preventDefault(); toggleSmallScreenMenu(event)">
193191
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
194192
viewBox="-20 -20 140 140">
195-
<g style="fill:#ffffff;stroke:none;">
193+
<g style="fill:#ffffff; fill:var(--header_text);stroke:none;">
196194
<circle cx="15" cy="20" r="5" />
197195
<circle cx="35" cy="20" r="5" />
198196
<circle cx="85" cy="20" r="5" />
@@ -221,38 +219,12 @@
221219
{%- endblock %}
222220

223221

224-
{%- block document %}
225-
<div class="documentwrapper">
226-
<div class="body" role="main">
227-
{% block body %} {% endblock %}
228-
{%- if title | lower == "index" %}
229-
<div class="siteindex"><div>
230-
231-
{%- for menu in menus %}
232-
{%- set menu_name = menu[1] %}
233-
{%- set sections = menu[2:] %}
234-
<h2>{{ menu_name }}</h2>
235-
<ul>
236-
{%- for section in sections %}
237-
{%- set url = section[0] %}
238-
{%- set entry = section[1] %}
239-
<li>
240-
<a href="{{ url }}">{{ entry }}</a>
241-
</li>
242-
{%- endfor %}
243-
</ul>
244-
{%- endfor %}
245-
246-
</div>
247-
{%- endif %}
248-
</div></div>
249-
</div>
250-
{%- endblock %}
251-
252-
253222

254223
{%- block footer %}
255224
<div class="footer">
225+
<div>
226+
<input type="button" id="themebutton" value="" onclick="switchTheme('')" />
227+
</div>
256228
<div>
257229
<a href="site.html">Site index</a>
258230
</div>
@@ -288,6 +260,30 @@ <h2>{{ menu_name }}</h2>
288260
for( var i=0; i<menus.length; i++ )
289261
menus[i].active = false;
290262

263+
// Manage theme
264+
var theme="light";
265+
function switchTheme(type) {
266+
if( type == "dark" || ( ! type && theme == "light" ) ) {
267+
theme = "dark";
268+
document.documentElement.setAttribute('theme', 'dark');
269+
window.name = "dark_theme"
270+
localStorage.setItem("_theme","dark")
271+
} else {
272+
theme = "light";
273+
document.documentElement.setAttribute('theme', 'light');
274+
window.name = "light_theme"
275+
localStorage.setItem("_theme","light")
276+
}
277+
}
278+
if( window.name && window.name == "light_theme" ) {
279+
switchTheme("light");
280+
} else if ( window.name && window.name == "dark_theme" ) {
281+
switchTheme("dark");
282+
} else if( stored_theme = localStorage.getItem("_theme") ) {
283+
switchTheme(stored_theme);
284+
} else if( window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
285+
switchTheme("dark");
286+
}
291287

292288
var ul = nav_list.getElementsByTagName("ul")[0], li;
293289
var keep_nav = false;
@@ -322,13 +318,24 @@ <h2>{{ menu_name }}</h2>
322318
}
323319

324320
function toggleSmallScreenMenu(e) {
325-
e.preventDefault();
326321
if( smallScreenMenu.className != "on" ) {
327322
smallScreenMenu.className = "on";
328323
smallScreenMenuButton.className = "pushed";
324+
document.documentElement.style.overflow = "hidden";
329325
} else {
330326
smallScreenMenu.className = "off";
331327
smallScreenMenuButton.className = "";
328+
document.documentElement.style.overflow = "";
329+
}
330+
}
331+
332+
if (smallScreenMenuAfterTOC = document.getElementById("smallScreenMenuAfterTOC")) {
333+
var smallScreenMenuTOC = smallScreenMenuAfterTOC.previousElementSibling
334+
.getElementsByTagName("li")[0].getElementsByTagName("ul")[0].getElementsByTagName("li");
335+
for (var i = 0; i < smallScreenMenuTOC.length; i++) {
336+
if (smallScreenMenuTOC[i].tagName = "a") {
337+
smallScreenMenuTOC[i].addEventListener("click", function(event){ toggleSmallScreenMenu(event); } );
338+
}
332339
}
333340
}
334341

0 commit comments

Comments
 (0)