11import itertools
22import pathlib
3+ import re
34
45from 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+
1221def _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();"> { tag . capitalize () } </label></li>'
39+ f'<li><label class="dropdown-item checkbox { tag_key } "><input type="checkbox" rel={ _make_class ( tag )} onchange="change();"> { 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 ' )])
0 commit comments