Skip to content

Commit b872d3b

Browse files
authored
Fix dropdown gallery filtering (#208)
* drop down menu without bullets * css and remove === * make subtext black * mess with javascript * jv edits * filtering working! * fix card margins, tag titling, and clear all filters * add all cookbooks back * fix merge conflicts * undo subtext changes
1 parent fec19d9 commit b872d3b

7 files changed

+162
-209
lines changed

site/_extensions/cookbook_gallery_generator.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from gallery_generator import build_from_repos, generate_menu, generate_repo_dicts
22

3-
43
def main(app):
54

65
with open("cookbook_gallery.txt") as fid:
@@ -25,6 +24,5 @@ def main(app):
2524
repo_dicts, "index", title=title, subtext=subtext, menu_html=menu_html
2625
)
2726

28-
2927
def setup(app):
30-
app.connect("builder-inited", main)
28+
app.connect("builder-inited", main)

site/_extensions/gallery_generator.py

+53-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import itertools, json, yaml, pathlib, subprocess, requests
22
from truncatehtml import truncate
3+
import re
34

45

56
def _grab_binder_link(repo):
@@ -113,14 +114,18 @@ def _generate_sorted_tag_keys(repo_dicts):
113114
return sorted(key_set)
114115

115116

117+
def _title_case_preserve(s):
118+
return re.sub(r'\b(\w)', lambda m: m.group(1).upper(), s)
119+
116120
def _generate_tag_set(repo_dicts, tag_key=None):
117121

118122
tag_set = set()
119123
for repo_dict in repo_dicts:
120124
for k, e in repo_dict["tags"].items():
125+
tags = [_title_case_preserve(t) for t in e]
121126
if tag_key and k != tag_key:
122127
continue
123-
for t in e:
128+
for t in tags:
124129
tag_set.add(t)
125130

126131
return tag_set
@@ -132,20 +137,18 @@ def _generate_tag_menu(repo_dicts, tag_key):
132137
tag_list = sorted(tag_set)
133138

134139
options = "".join(
135-
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={tag.replace(" ", "-")} onchange="change();">&nbsp;{tag}</label></li>'
140+
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={tag.replace(" ", "-").lower()} onchange="change();">&nbsp;{tag}</label></li>'
136141
for tag in tag_list
137142
)
138143

139144
return f"""
140-
<div class="dropdown">
141-
142-
<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">
143-
{tag_key.title()}
144-
</button>
145-
<ul class="dropdown-menu" aria-labelledby="{tag_key}Dropdown">
146-
{options}
147-
</ul>
148-
</div>
145+
:::{{dropdown}} {tag_key}
146+
<div class="dropdown">
147+
<ul>
148+
{options}
149+
</ul>
150+
</div>
151+
:::
149152
"""
150153

151154

@@ -200,12 +203,11 @@ def build_from_repos(
200203
tag_list = sorted((itertools.chain(*tag_dict.values())))
201204
tag_list_f = [tag.replace(" ", "-") for tag in tag_list]
202205
tags = [
203-
f'<span class="badge bg-primary mybadges">{tag}</span>'
206+
f'<span class="badge bg-primary mybadges">{_title_case_preserve(tag)}</span>'
204207
for tag in tag_list_f
205208
]
206209
tags = "\n".join(tags)
207-
208-
# tag_class_str = " ".join(tag_list_f)
210+
tag_classes = " ".join(tag_list_f)
209211

210212
description = repo_dict["description"]
211213
ellipsis_str = '<a class="modal-btn"> ... more</a>'
@@ -214,53 +216,53 @@ def build_from_repos(
214216
if ellipsis_str in short_description:
215217
modal_str = f"""
216218
<div class="modal">
217-
<div class="content">
218-
<img src="{thumbnail_url}" class="modal-img" />
219-
<h3 class="display-3">{cookbook_title}</h3>
220-
{authors_str}
221-
<p class="my-2">{description}</p>
222-
<p class="my-2">{tags}</p>
223-
<p class="mt-3 mb-0"><a href="{cookbook_url}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
224-
</div>
219+
<div class="content">
220+
<img src="{thumbnail_url}" class="modal-img" />
221+
<h3 class="display-3">{cookbook_title}</h3>
222+
{authors_str}
223+
<p class="my-2">{description}</p>
224+
<p class="my-2">{tags}</p>
225+
<p class="mt-3 mb-0"><a href="{cookbook_url}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
226+
</div>
225227
</div>
226228
"""
227229
modal_str = '\n'.join([m.lstrip() for m in modal_str.split('\n')])
228230
else:
229231
modal_str = ""
230-
231-
new_card = f"""\
232-
:::{{grid-item-card}}
233-
:shadow: md
234-
:class-footer: card-footer
235-
<div class="d-flex gallery-card">
236-
<img src="{thumbnail_url}" class="gallery-thumbnail" />
237-
<div class="container">
238-
<a href="{cookbook_url}" class="text-decoration-none"><h4 class="display-4 p-0">{cookbook_title}</h4></a>
239-
<p class="card-subtitle">{authors_str}</p>
240-
<p class="my-2">{short_description} </p>
241-
</div>
242-
</div>
243-
{modal_str}
244-
245-
+++
246-
247-
<div class="tagsandbadges">
248-
{tags}
249-
<div>{status_badges}</div>
250-
</div>
251-
252-
:::
253-
254-
"""
255232

256-
grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))
233+
new_card = f"""
234+
:::{{grid-item-card}}
235+
:shadow: md
236+
:class-footer: card-footer
237+
:class-card: tagged-card {tag_classes}
238+
239+
<div class="d-flex gallery-card">
240+
<img src="{thumbnail_url}" class="gallery-thumbnail" />
241+
<div class="container">
242+
<a href="{cookbook_url}" class="text-decoration-none"><h4 class="display-4 p-0">{cookbook_title}</h4></a>
243+
<p class="card-subtitle">{authors_str}</p>
244+
<p class="my-2">{short_description} </p>
245+
</div>
246+
</div>
247+
{modal_str}
248+
249+
+++
250+
251+
<div class="tagsandbadges">
252+
{tags}
253+
<div>{status_badges}</div>
254+
</div>
255+
:::
256+
"""
257257

258+
grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))
258259

259-
grid_body = "\n".join(grid_body)
260260

261261
stitle = f"#### {subtitle}" if subtitle else ""
262262
stext = subtext if subtext else ""
263263

264+
grid_body = "\n".join(grid_body)
265+
264266
grid = f"""
265267
# {title}
266268
@@ -270,12 +272,12 @@ def build_from_repos(
270272
{menu_html}
271273
272274
::::{{grid}} 1
273-
:gutter: 4
275+
:gutter: 0
274276
275277
{grid_body}
276278
277279
<div class="modal-backdrop"></div>
278-
<script src="/_static/custom.js"></script>
280+
<script src="../html/_static/custom.js"></script>
279281
"""
280282

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

site/_static/custom.css

+46
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,49 @@ main.banner-main #project-pythia {
153153
.tagsandbadges {
154154
padding: 0 0;
155155
}
156+
157+
.dropdown ul {
158+
list-style: none;
159+
padding: 0;
160+
margin: 0;
161+
}
162+
163+
.dropdown-item {
164+
display: block;
165+
}
166+
167+
.dropdown-item input[type="checkbox"] {
168+
margin-right: 0.5em;
169+
}
170+
171+
details.sd-dropdown {
172+
box-shadow: none !important;
173+
}
174+
175+
details.sd-dropdown summary.sd-card-header + div.sd-summary-content {
176+
background-color: white !important;
177+
border: 0.2rem solid var(--pst-sd-dropdown-color) !important;
178+
border-radius: calc(.25rem - 1px);
179+
}
180+
181+
.bd-content .sd-card .sd-card-header {
182+
background-color: var(--pst-color-panel-background) !important;
183+
}
184+
185+
.sd-summary-content.sd-card-body.docutils {
186+
position: absolute;
187+
z-index: 100;
188+
}
189+
190+
details.sd-dropdown summary.sd-card-header {
191+
border: 0.2rem solid var(--pst-sd-dropdown-color) !important;
192+
border-radius: calc(.25rem - 1px);
193+
}
194+
195+
p {
196+
color: black;
197+
}
198+
199+
.sd-col.sd-d-flex-row.docutils.has-visible-card {
200+
margin-bottom: 1rem;
201+
}

0 commit comments

Comments
 (0)