Skip to content

Commit e9b00ce

Browse files
committed
Major changes: Include extensions lightbox and accordion, several text revisions
1 parent ce484cf commit e9b00ce

File tree

23 files changed

+590
-207
lines changed

23 files changed

+590
-207
lines changed

docs/_static/custom.css

Lines changed: 152 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,88 @@
1+
/*
2+
Modifications for the Sphinx based Read the Docs theme sphinx_rtd_theme.
3+
Changes are made in order to adhere to University of Copenhagen's style guide.
4+
*/
5+
a {
6+
color: #679c5b;
7+
}
8+
9+
body {
10+
font-family: "Open Sans",Helvetica,Arial,sans-serif
11+
}
12+
.wy-side-nav-search {background-color: white;}
13+
.wy-menu-vertical a {color: #252525;}
14+
.wy-menu-vertical li.current > a {color:#901a1e;}
15+
16+
.wy-menu-vertical a:hover {
17+
background-color:#eee;
18+
cursor:pointer;
19+
color: #901a1e !important;
20+
}
21+
.wy-menu-vertical p.caption {color: #252525;}
22+
23+
.wy-menu-vertical li.toctree-l2.current li.toctree-l3 > a {background: #eee;border:0;}
24+
@media screen and (max-width: 1100px) {
25+
.wy-nav-content-wrap {
26+
margin-left: 0;
27+
}
28+
29+
.wy-nav-side {
30+
left: -300px;
31+
}
32+
33+
.wy-nav-side.shift {
34+
left: 0px;
35+
width: 300px;
36+
background: unset;
37+
}
38+
39+
.wy-nav-content-wrap.shift {
40+
position: fixed;
41+
min-width: 100%;
42+
left: 300px;
43+
top: 0;
44+
height: 100%;
45+
overflow: hidden;
46+
}
147

48+
.wy-menu.wy-menu-vertical, .wy-side-nav-search, .wy-side-scroll {
49+
width: 300px;
50+
}
51+
52+
.wy-nav-top {
53+
display: block;
54+
background: white;
55+
}
56+
57+
[data-toggle="wy-nav-top"] {
58+
color: #404040;
59+
}
60+
61+
nav.wy-nav-top a {
62+
color: #404040;
63+
font-family: Roboto Slab,ff-tisa-web-pro,Georgia,Arial,sans-serif;
64+
font-size: 200%;
65+
}
66+
}
67+
68+
@media screen and (min-width: 1100px) {
69+
.wy-grid-for-nav nav {
70+
background: white;
71+
}
72+
}
73+
74+
/* Distinguishing images from text content */
75+
.rst-content img.with-border {
76+
border-color: lightgrey;
77+
border-width: 2px;
78+
border-style: solid;
79+
}
80+
81+
82+
.wy-nav-content a {
83+
color: #2c6694;
84+
text-decoration: underline;
85+
286
a {
387
color: #679c5b;
488
}
@@ -37,7 +121,7 @@ body {
37121

38122
.wy-nav-top {
39123
display: block;
40-
background: #c9c9c9;
124+
background: white;
41125
}
42126

43127
[data-toggle="wy-nav-top"] {
@@ -64,57 +148,83 @@ body {
64148
border-style: solid;
65149
}
66150

67-
/* Details expand-collaps boxes
68-
summary {
69-
list-style: none;
70-
display: flex;
71-
justify-content: space-between;
72-
align-items: center;
73-
font-weight: bold;
74-
width: 100%;
75-
font-size: 15px;
76-
background: lightgrey;
77-
padding: 3px 2px 0 5px;
78-
} */
151+
79152
.wy-nav-content a {
80-
color: #666 !important;
81-
}
82-
/*
83-
summary::after {
84-
content: '';
85-
width: 18px;
86-
height: 10px;
87-
background: url('arrow_down.svg') no-repeat;
88-
background-size: 14px;
89-
margin-left: .75em;
90-
transition: 0.2s;
153+
color: #666 !important;
154+
155+
a {
156+
color: #679c5b;
91157
}
92158

93-
details[open] > summary::after {
94-
transform: rotate(180deg);
95-
position: relative;
96-
bottom: 2px;
97-
right: 4px;
159+
body {
160+
font-family: "Open Sans",Helvetica,Arial,sans-serif
98161
}
99162

100-
summary::-webkit-details-marker {
101-
display: none;
102-
}
163+
@media screen and (max-width: 1100px) {
164+
.wy-nav-content-wrap {
165+
margin-left: 0;
166+
}
167+
168+
.wy-nav-side {
169+
left: -300px;
170+
}
103171

104-
summary {
105-
border-radius: 0px;
172+
.wy-nav-side.shift {
173+
left: 0px;
174+
width: 300px;
175+
background: unset;
176+
}
177+
178+
.wy-nav-content-wrap.shift {
179+
position: fixed;
180+
min-width: 100%;
181+
left: 300px;
182+
top: 0;
183+
height: 100%;
184+
overflow: hidden;
185+
}
186+
187+
.wy-menu.wy-menu-vertical, .wy-side-nav-search, .wy-side-scroll {
188+
width: 300px;
189+
}
190+
191+
.wy-nav-top {
192+
display: block;
193+
background: white;
194+
}
195+
196+
[data-toggle="wy-nav-top"] {
197+
color: #404040;
198+
}
199+
200+
nav.wy-nav-top a {
201+
color: #404040;
202+
font-family: Roboto Slab,ff-tisa-web-pro,Georgia,Arial,sans-serif;
203+
font-size: 200%;
204+
}
106205
}
107206

108-
details[open] summary {
109-
border-radius: 0px 0px 0 0;
207+
@media screen and (min-width: 1100px) {
208+
.wy-grid-for-nav nav {
209+
background: white;
210+
}
110211
}
111212

112-
details {
113-
border-radius: 0px;
114-
border: 1px solid #666;
115-
margin-bottom: 10px;
213+
/* Distinguishing images from text content */
214+
.rst-content img.with-border {
215+
border-color: lightgrey;
216+
border-width: 2px;
217+
border-style: solid;
218+
}
219+
220+
221+
.wy-nav-content a {
222+
color: #2c6694;
223+
text-decoration: underline;
224+
}
225+
116226
}
117-
*/
227+
118228

119229
/* Coloring */
120230
.rst-content .note .admonition-title,
@@ -200,13 +310,9 @@ details {
200310
background: lightgrey
201311
}
202312

203-
.wy-menu-vertical a:hover {
204-
background-color:lightgray;
205-
cursor:pointer
206-
}
207313

208314
.wy-side-nav-search {
209-
background: white;
315+
background: white !important;
210316
}
211317

212318
.wy-side-nav-search input[type="text"] {
33.6 KB
Loading

docs/extensions/lightbox/lightbox.css

Whitespace-only changes.

docs/extensions/lightbox/lightbox.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Lightbox(Directive):
4040
.. lightbox:: path/to/image.jpg
4141
:alt: Alternative text for the image
4242
:caption: A caption for the image
43-
:percentage: 50 80
43+
:percentage: 50 80 95
44+
:class: border-box
4445
"""
4546

4647
has_content = True
@@ -51,8 +52,10 @@ class Lightbox(Directive):
5152
'alt': directives.unchanged,
5253
'caption': directives.unchanged,
5354
'percentage': directives.positive_int_list,
55+
'class': directives.unchanged,
5456
}
5557

58+
5659
def run(self):
5760
"""
5861
Create a lightbox element.
@@ -65,26 +68,38 @@ def run(self):
6568
alt_text = self.options.get('alt', '')
6669
caption = self.options.get('caption', '')
6770
percentages = self.options.get('percentage', [])
71+
custom_class = self.options.get('class', '')
6872

73+
# Set default values for thumbnail_width, lightbox_width, and height_style. Can be overridden by percentage option.
74+
# Initial value uses full width, or with of the image.
6975
thumbnail_width = '100%'
70-
lightbox_width = '100%'
76+
# Initial value uses 95 % of width, specifically to allow for Close image icon.
77+
# Initial value uses 95 % of height, specifically to allow for caption text.
7178

79+
# Inside the run() method
7280
if percentages:
73-
# The first percentage is the thumbnail width according to container width.
7481
thumbnail_width = f'{percentages[0]}%'
7582
if len(percentages) > 1:
76-
# vw is a CSS unit that represents a percentage of the viewport width
77-
lightbox_width = f'{percentages[1]}vw'
83+
scale_percentage = percentages[1]
84+
# Use min() function in CSS to automatically choose the constraining dimension
85+
size_style = f"""
86+
width: min({scale_percentage}vw, calc({scale_percentage}vh * var(--aspect-ratio)));
87+
height: min({scale_percentage}vh, calc({scale_percentage}vw / var(--aspect-ratio)));
88+
"""
7889

7990
# Generate a unique ID for the checkbox
8091
checkbox_id = f"lightbox-{env.new_serialno('lightbox')}"
8192

8293
# Construct the full source path
8394
src_image_path = os.path.join(env.srcdir, image_path)
8495

85-
# Copy the image to _static directory
96+
# Copy the image to _static directory while preserving subdirectories
8697
static_dir = '_static'
87-
new_image_path = os.path.join(static_dir, os.path.basename(image_path))
98+
rel_path = os.path.relpath(image_path)
99+
new_image_path = os.path.join(static_dir, rel_path)
100+
101+
# Create subdirectories if they don't exist
102+
os.makedirs(os.path.dirname(os.path.join(env.app.outdir, new_image_path)), exist_ok=True)
88103

89104
try:
90105
copy_asset_file(src_image_path, os.path.join(env.app.outdir, new_image_path))
@@ -95,24 +110,28 @@ def run(self):
95110
# Generate the correct relative path
96111
current_page_path = env.docname
97112
image_url = relative_uri(current_page_path, new_image_path)
98-
99113
# Use image_url in your HTML generation
100114
html = f"""
101115
<label for="{checkbox_id}">
102-
<img src="{image_url}" alt="{alt_text}" class="lightbox-trigger" style="width: {thumbnail_width};">
116+
<img src="{image_url}" alt="{alt_text}" class="lightbox-trigger {custom_class}"
117+
style="width: {thumbnail_width};">
103118
</label>
104119
<input type="checkbox" id="{checkbox_id}" class="lightbox-toggle">
105120
<div class="lightbox">
106-
<label for="{checkbox_id}" class="close-btn">×</label>
107121
<label for="{checkbox_id}">
108-
<div class="lightbox-content">
109-
<img src="{image_url}" alt="{alt_text}" style="width: {lightbox_width};">
110-
<p class="lightbox-caption">{caption}</p>
122+
<div class="lightbox-content" style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
123+
<div class="image-container" style="text-align: center;">
124+
<img src="{image_url}" alt="{alt_text}" class="{custom_class}" style="{size_style}"
125+
onload="this.style.setProperty('--aspect-ratio', this.naturalWidth / this.naturalHeight);">
126+
<div class="caption-overlay" style="text-align: center;">{caption}</div>
127+
<label for="{checkbox_id}" class="close-btn-overlay">×</label>
128+
</div>
129+
<p class="caption-below" style="text-align: center;">{caption}</p>
130+
<label for="{checkbox_id}" class="close-btn-side">×</label>
111131
</div>
112132
</label>
113133
</div>
114134
"""
115-
116135
return [nodes.raw('', html, format='html')]
117136

118137
def setup(app):

0 commit comments

Comments
 (0)