Skip to content

Commit 16383cb

Browse files
dropdown gallery changes (ProjectPythia#444)
* dropdown gallery changes * fix indent * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * dark theme changes * dark theme cards * them to theme * rm accidental link color chagne --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 44e4d7e commit 16383cb

File tree

4 files changed

+195
-206
lines changed

4 files changed

+195
-206
lines changed

portal/_extensions/gallery_generator.py

+53-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import itertools
22
import pathlib
3+
import re
34

45
from truncatehtml import truncate
56

@@ -9,13 +10,22 @@ def _generate_sorted_tag_keys(all_items):
910
return sorted(key_set)
1011

1112

13+
def _title_case_preserve(s):
14+
return re.sub(r'\b(\w)', lambda m: m.group(1).upper(), s)
15+
16+
17+
def _make_class(s):
18+
return re.sub(r'^\d+', '', s.replace(' ', '-').lower())
19+
20+
1221
def _generate_tag_set(all_items, tag_key=None):
1322
tag_set = set()
1423
for item in all_items:
1524
for k, e in item['tags'].items():
25+
tags = [_title_case_preserve(t) for t in e]
1626
if tag_key and k != tag_key:
1727
continue
18-
for t in e:
28+
for t in tags:
1929
tag_set.add(t)
2030

2131
return tag_set
@@ -26,20 +36,18 @@ def _generate_tag_menu(all_items, tag_key):
2636
tag_list = sorted(tag_set)
2737

2838
options = ''.join(
29-
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={tag.replace(" ", "-")} onchange="change();">&nbsp;{tag.capitalize()}</label></li>'
39+
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={_make_class(tag)} onchange="change();">&nbsp;{tag}</label></li>'
3040
for tag in tag_list
3141
)
3242

3343
return f"""
34-
<div class="dropdown">
35-
36-
<button class="btn btn-sm btn-outline-primary mx-1 dropdown-toggle" type="button" id="{tag_key}Dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
37-
{tag_key.title()}
38-
</button>
39-
<ul class="dropdown-menu" aria-labelledby="{tag_key}Dropdown">
40-
{options}
41-
</ul>
42-
</div>
44+
:::{{dropdown}} {tag_key}
45+
<div class="dropdown">
46+
<ul>
47+
{options}
48+
</ul>
49+
</div>
50+
:::
4351
"""
4452

4553

@@ -71,10 +79,9 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
7179
tag_list = sorted((itertools.chain(*item['tags'].values())))
7280
tag_list_f = [tag.replace(' ', '-') for tag in tag_list]
7381

74-
tags = [f'<span class="badge bg-primary">{tag}</span>' for tag in tag_list_f]
82+
tags = [f'<span class="badge bg-primary mybadges">{_title_case_preserve(tag)}</span>' for tag in tag_list_f]
7583
tags = '\n'.join(tags)
76-
77-
# tag_class_str = ' '.join(tag_list_f)
84+
tag_classes = ' '.join(tag_list_f)
7885

7986
author_strs = set()
8087
affiliation_strs = set()
@@ -108,51 +115,52 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
108115
if ellipsis_str in short_description:
109116
modal_str = f"""
110117
<div class="modal">
111-
<div class="content">
112-
<img src="{thumbnail}" class="modal-img" />
113-
<h3 class="display-3">{item["title"]}</h3>
114-
{authors_str}
115-
<br/>
116-
{affiliations_str}
117-
<p class="my-2">{item['description']}</p>
118-
<p class="my-2">{tags}</p>
119-
<p class="mt-3 mb-0"><a href="{item["url"]}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
120-
</div>
118+
<div class="content">
119+
<img src="{thumbnail}" class="modal-img" />
120+
<h3 class="display-3">{item["title"]}</h3>
121+
{authors_str}
122+
<br/>
123+
{affiliations_str}
124+
<p class="my-2">{item['description']}</p>
125+
<p class="my-2">{tags}</p>
126+
<p class="mt-3 mb-0"><a href="{item["url"]}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
127+
</div>
121128
</div>
122129
"""
123130
modal_str = '\n'.join([m.lstrip() for m in modal_str.split('\n')])
124131
else:
125132
modal_str = ''
126133

127-
new_card = f"""\
128-
:::{{grid-item-card}}
129-
:shadow: md
130-
:class-footer: card-footer
131-
<div class="d-flex gallery-card">
132-
<img src="{thumbnail}" class="gallery-thumbnail" />
133-
<div class="container">
134-
<a href="{item["url"]}" class="text-decoration-none"><h4 class="display-4 p-0">{item["title"]}</h4></a>
135-
<p class="card-subtitle">{authors_str}<br/>{affiliations_str}</p>
136-
<p class="my-2">{short_description} </p>
137-
</div>
138-
</div>
139-
{modal_str}
134+
new_card = f"""
135+
:::{{grid-item-card}}
136+
:shadow: md
137+
:class-footer: card-footer
138+
:class-card: tagged-card {tag_classes}
140139
141-
+++
140+
<div class="d-flex gallery-card">
141+
<img src="{thumbnail}" class="gallery-thumbnail" />
142+
<div class="container">
143+
<a href="{item["url"]}" class="text-decoration-none"><h4 class="display-4 p-0">{item["title"]}</h4></a>
144+
<p class="card-subtitle">{authors_str}<br/>{affiliations_str}</p>
145+
<p class="my-2">{short_description} </p>
146+
</div>
147+
</div>
148+
{modal_str}
142149
143-
{tags}
150+
+++
144151
145-
:::
152+
{tags}
146153
147-
"""
154+
:::
148155
149-
grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))
156+
"""
150157

151-
grid_body = '\n'.join(grid_body)
158+
grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))
152159

153160
stitle = f'#### {subtitle}' if subtitle else ''
154161
stext = subtext if subtext else ''
155162

163+
grid_body = '\n'.join(grid_body)
156164
grid = f"""\
157165
{title}
158166
{'=' * len(title)}
@@ -163,12 +171,12 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
163171
{menu_html}
164172
165173
::::{{grid}} 1
166-
:gutter: 4
174+
:gutter: 0
167175
168176
{grid_body}
169177
170178
<div class="modal-backdrop"></div>
171-
<script src="/_static/custom.js"></script>
179+
<script src="../html/_static/custom.js"></script>
172180
"""
173181

174182
grid = '\n'.join([m.lstrip() for m in grid.split('\n')])

portal/_static/custom.css

+66
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,69 @@ div.horizontalgap {
144144
height: 1px;
145145
width: 0px;
146146
}
147+
148+
.dropdown ul {
149+
list-style: none;
150+
padding: 0;
151+
margin: 0;
152+
}
153+
154+
.dropdown-item {
155+
display: block;
156+
}
157+
158+
.dropdown-item input[type="checkbox"] {
159+
margin-right: 0.5em;
160+
}
161+
162+
details.sd-dropdown {
163+
box-shadow: none !important;
164+
}
165+
166+
details.sd-dropdown summary.sd-card-header + div.sd-summary-content {
167+
background-color: white !important;
168+
border: 0.2rem solid var(--pst-sd-dropdown-color) !important;
169+
border-radius: calc(.25rem - 1px);
170+
}
171+
172+
.sd-summary-content.sd-card-body.docutils {
173+
position: absolute;
174+
z-index: 100;
175+
}
176+
177+
details.sd-dropdown:not([open])>.sd-card-header {
178+
background-color: white !important;
179+
border: 2px solid #1a648f !important;
180+
color: #1a648f;
181+
border-radius: .5rem;
182+
}
183+
184+
details.sd-dropdown[open]>.sd-card-header {
185+
background-color: #1a648f !important;
186+
color: white;
187+
border-radius: .5rem;
188+
}
189+
190+
p {
191+
color: black;
192+
}
193+
194+
.sd-col.sd-d-flex-row.docutils.has-visible-card {
195+
margin-bottom: 1rem;
196+
}
197+
198+
html[data-theme="dark"] h1.display-1 {
199+
color: white;
200+
}
201+
202+
html[data-them="dark"] h4.display-4.p-0 {
203+
color: black !important;
204+
}
205+
206+
html[data-theme="dark"] .sd-card-body.docutils {
207+
background-color: white;
208+
}
209+
210+
html[data-theme="dark"] .container p {
211+
color: black !important;
212+
}

0 commit comments

Comments
 (0)