Skip to content

Commit 1ceb7cc

Browse files
committed
dropdown gallery changes
1 parent a805576 commit 1ceb7cc

File tree

4 files changed

+197
-223
lines changed

4 files changed

+197
-223
lines changed

portal/_extensions/gallery_generator.py

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import itertools
22
import pathlib
3-
3+
import re
44
from truncatehtml import truncate
55

66

@@ -9,13 +9,20 @@ def _generate_sorted_tag_keys(all_items):
99
return sorted(key_set)
1010

1111

12+
def _title_case_preserve(s):
13+
return re.sub(r'\b(\w)', lambda m: m.group(1).upper(), s)
14+
15+
def _make_class(s):
16+
return re.sub(r'^\d+', '', s.replace(" ", "-").lower())
17+
1218
def _generate_tag_set(all_items, tag_key=None):
1319
tag_set = set()
1420
for item in all_items:
1521
for k, e in item['tags'].items():
22+
tags = [_title_case_preserve(t) for t in e]
1623
if tag_key and k != tag_key:
1724
continue
18-
for t in e:
25+
for t in tags:
1926
tag_set.add(t)
2027

2128
return tag_set
@@ -26,20 +33,18 @@ def _generate_tag_menu(all_items, tag_key):
2633
tag_list = sorted(tag_set)
2734

2835
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>'
36+
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={_make_class(tag)} onchange="change();">&nbsp;{tag}</label></li>'
3037
for tag in tag_list
31-
)
38+
)
3239

3340
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>
41+
:::{{dropdown}} {tag_key}
42+
<div class="dropdown">
43+
<ul>
44+
{options}
45+
</ul>
46+
</div>
47+
:::
4348
"""
4449

4550

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

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

7983
author_strs = set()
8084
affiliation_strs = set()
@@ -108,50 +112,51 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
108112
if ellipsis_str in short_description:
109113
modal_str = f"""
110114
<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>
115+
<div class="content">
116+
<img src="{thumbnail}" class="modal-img" />
117+
<h3 class="display-3">{item["title"]}</h3>
118+
{authors_str}
119+
<br/>
120+
{affiliations_str}
121+
<p class="my-2">{item['description']}</p>
122+
<p class="my-2">{tags}</p>
123+
<p class="mt-3 mb-0"><a href="{item["url"]}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
124+
</div>
121125
</div>
122126
"""
123127
modal_str = '\n'.join([m.lstrip() for m in modal_str.split('\n')])
124128
else:
125129
modal_str = ''
126-
new_card = f"""\
127-
:::{{grid-item-card}}
128-
:shadow: md
129-
:class-footer: card-footer
130-
<div class="d-flex gallery-card">
131-
<img src="{thumbnail}" class="gallery-thumbnail" />
132-
<div class="container">
133-
<a href="{item["url"]}" class="text-decoration-none"><h4 class="display-4 p-0">{item["title"]}</h4></a>
134-
<p class="card-subtitle">{authors_str}<br/>{affiliations_str}</p>
135-
<p class="my-2">{short_description} </p>
136-
</div>
137-
</div>
138-
{modal_str}
130+
new_card = f"""
131+
:::{{grid-item-card}}
132+
:shadow: md
133+
:class-footer: card-footer
134+
:class-card: tagged-card {tag_classes}
139135
140-
+++
136+
<div class="d-flex gallery-card">
137+
<img src="{thumbnail}" class="gallery-thumbnail" />
138+
<div class="container">
139+
<a href="{item["url"]}" class="text-decoration-none"><h4 class="display-4 p-0">{item["title"]}</h4></a>
140+
<p class="card-subtitle">{authors_str}<br/>{affiliations_str}</p>
141+
<p class="my-2">{short_description} </p>
142+
</div>
143+
</div>
144+
{modal_str}
141145
142-
{tags}
146+
+++
143147
144-
:::
148+
{tags}
145149
146-
"""
150+
:::
147151
148-
grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))
152+
"""
149153

150-
grid_body = '\n'.join(grid_body)
154+
grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))
151155

152156
stitle = f'#### {subtitle}' if subtitle else ''
153157
stext = subtext if subtext else ''
154158

159+
grid_body = "\n".join(grid_body)
155160
grid = f"""\
156161
{title}
157162
{'=' * len(title)}
@@ -162,12 +167,12 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
162167
{menu_html}
163168
164169
::::{{grid}} 1
165-
:gutter: 4
170+
:gutter: 0
166171
167172
{grid_body}
168173
169174
<div class="modal-backdrop"></div>
170-
<script src="/_static/custom.js"></script>
175+
<script src="../html/_static/custom.js"></script>
171176
"""
172177

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

portal/_static/custom.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,57 @@ 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+
main.bd-content #main-content a {
195+
color: #1a648f;
196+
}
197+
198+
.sd-col.sd-d-flex-row.docutils.has-visible-card {
199+
margin-bottom: 1rem;
200+
}

0 commit comments

Comments
 (0)