1
1
import itertools , json , yaml , pathlib , subprocess , requests
2
2
from truncatehtml import truncate
3
+ import re
3
4
4
5
5
6
def _grab_binder_link (repo ):
@@ -113,14 +114,18 @@ def _generate_sorted_tag_keys(repo_dicts):
113
114
return sorted (key_set )
114
115
115
116
117
+ def _title_case_preserve (s ):
118
+ return re .sub (r'\b(\w)' , lambda m : m .group (1 ).upper (), s )
119
+
116
120
def _generate_tag_set (repo_dicts , tag_key = None ):
117
121
118
122
tag_set = set ()
119
123
for repo_dict in repo_dicts :
120
124
for k , e in repo_dict ["tags" ].items ():
125
+ tags = [_title_case_preserve (t ) for t in e ]
121
126
if tag_key and k != tag_key :
122
127
continue
123
- for t in e :
128
+ for t in tags :
124
129
tag_set .add (t )
125
130
126
131
return tag_set
@@ -132,20 +137,18 @@ def _generate_tag_menu(repo_dicts, tag_key):
132
137
tag_list = sorted (tag_set )
133
138
134
139
options = "" .join (
135
- f'<li><label class="dropdown-item checkbox { tag_key } "><input type="checkbox" rel={ tag .replace (" " , "-" )} onchange="change();"> { tag } </label></li>'
140
+ f'<li><label class="dropdown-item checkbox { tag_key } "><input type="checkbox" rel={ tag .replace (" " , "-" ). lower () } onchange="change();"> { tag } </label></li>'
136
141
for tag in tag_list
137
142
)
138
143
139
144
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
+ :::
149
152
"""
150
153
151
154
@@ -200,12 +203,11 @@ def build_from_repos(
200
203
tag_list = sorted ((itertools .chain (* tag_dict .values ())))
201
204
tag_list_f = [tag .replace (" " , "-" ) for tag in tag_list ]
202
205
tags = [
203
- f'<span class="badge bg-primary mybadges">{ tag } </span>'
206
+ f'<span class="badge bg-primary mybadges">{ _title_case_preserve ( tag ) } </span>'
204
207
for tag in tag_list_f
205
208
]
206
209
tags = "\n " .join (tags )
207
-
208
- # tag_class_str = " ".join(tag_list_f)
210
+ tag_classes = " " .join (tag_list_f )
209
211
210
212
description = repo_dict ["description" ]
211
213
ellipsis_str = '<a class="modal-btn"> ... more</a>'
@@ -214,53 +216,53 @@ def build_from_repos(
214
216
if ellipsis_str in short_description :
215
217
modal_str = f"""
216
218
<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>
225
227
</div>
226
228
"""
227
229
modal_str = '\n ' .join ([m .lstrip () for m in modal_str .split ('\n ' )])
228
230
else :
229
231
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
- """
255
232
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
+ """
257
257
258
+ grid_body .append ('\n ' .join ([m .lstrip () for m in new_card .split ('\n ' )]))
258
259
259
- grid_body = "\n " .join (grid_body )
260
260
261
261
stitle = f"#### { subtitle } " if subtitle else ""
262
262
stext = subtext if subtext else ""
263
263
264
+ grid_body = "\n " .join (grid_body )
265
+
264
266
grid = f"""
265
267
# { title }
266
268
@@ -270,12 +272,12 @@ def build_from_repos(
270
272
{ menu_html }
271
273
272
274
::::{{grid}} 1
273
- :gutter: 4
275
+ :gutter: 0
274
276
275
277
{ grid_body }
276
278
277
279
<div class="modal-backdrop"></div>
278
- <script src="/_static/custom.js"></script>
280
+ <script src="../html /_static/custom.js"></script>
279
281
"""
280
282
281
283
grid = '\n ' .join ([m .lstrip () for m in grid .split ('\n ' )])
0 commit comments