1
1
import itertools
2
2
import pathlib
3
-
3
+ import re
4
4
from truncatehtml import truncate
5
5
6
6
@@ -9,13 +9,20 @@ def _generate_sorted_tag_keys(all_items):
9
9
return sorted (key_set )
10
10
11
11
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
+
12
18
def _generate_tag_set (all_items , tag_key = None ):
13
19
tag_set = set ()
14
20
for item in all_items :
15
21
for k , e in item ['tags' ].items ():
22
+ tags = [_title_case_preserve (t ) for t in e ]
16
23
if tag_key and k != tag_key :
17
24
continue
18
- for t in e :
25
+ for t in tags :
19
26
tag_set .add (t )
20
27
21
28
return tag_set
@@ -26,20 +33,18 @@ def _generate_tag_menu(all_items, tag_key):
26
33
tag_list = sorted (tag_set )
27
34
28
35
options = '' .join (
29
- f'<li><label class="dropdown-item checkbox { tag_key } "><input type="checkbox" rel={ tag . replace ( " " , "-" )} onchange="change();"> { tag . capitalize () } </label></li>'
36
+ f'<li><label class="dropdown-item checkbox { tag_key } "><input type="checkbox" rel={ _make_class ( tag )} onchange="change();"> { tag } </label></li>'
30
37
for tag in tag_list
31
- )
38
+ )
32
39
33
40
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
+ :::
43
48
"""
44
49
45
50
@@ -71,10 +76,9 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
71
76
tag_list = sorted ((itertools .chain (* item ['tags' ].values ())))
72
77
tag_list_f = [tag .replace (' ' , '-' ) for tag in tag_list ]
73
78
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 ]
75
80
tags = '\n ' .join (tags )
76
-
77
- # tag_class_str = ' '.join(tag_list_f)
81
+ tag_classes = " " .join (tag_list_f )
78
82
79
83
author_strs = set ()
80
84
affiliation_strs = set ()
@@ -108,50 +112,51 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
108
112
if ellipsis_str in short_description :
109
113
modal_str = f"""
110
114
<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>
121
125
</div>
122
126
"""
123
127
modal_str = '\n ' .join ([m .lstrip () for m in modal_str .split ('\n ' )])
124
128
else :
125
129
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 }
139
135
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 }
141
145
142
- { tags }
146
+ +++
143
147
144
- :::
148
+ { tags }
145
149
146
- """
150
+ :::
147
151
148
- grid_body . append ( ' \n ' . join ([ m . lstrip () for m in new_card . split ( ' \n ' )]))
152
+ """
149
153
150
- grid_body = '\n ' .join (grid_body )
154
+ grid_body . append ( '\n ' .join ([ m . lstrip () for m in new_card . split ( ' \n ' )]) )
151
155
152
156
stitle = f'#### { subtitle } ' if subtitle else ''
153
157
stext = subtext if subtext else ''
154
158
159
+ grid_body = "\n " .join (grid_body )
155
160
grid = f"""\
156
161
{ title }
157
162
{ '=' * len (title )}
@@ -162,12 +167,12 @@ def build_from_items(items, filename, title='Gallery', subtitle=None, subtext=No
162
167
{ menu_html }
163
168
164
169
::::{{grid}} 1
165
- :gutter: 4
170
+ :gutter: 0
166
171
167
172
{ grid_body }
168
173
169
174
<div class="modal-backdrop"></div>
170
- <script src="/_static/custom.js"></script>
175
+ <script src="../html /_static/custom.js"></script>
171
176
"""
172
177
173
178
grid = '\n ' .join ([m .lstrip () for m in grid .split ('\n ' )])
0 commit comments