|
| 1 | +import itertools |
1 | 2 | import pathlib
|
2 | 3 | from textwrap import dedent
|
3 | 4 |
|
|
7 | 8 | def _tag_in_item(item, tag_str=None):
|
8 | 9 | if tag_str is None:
|
9 | 10 | return True
|
10 |
| - all_tags = [] |
11 |
| - for k, e in item['tags'].items(): |
12 |
| - all_tags.extend(e) |
| 11 | + all_tags = list(item['tags'].values()) |
13 | 12 | return tag_str in all_tags
|
14 | 13 |
|
15 | 14 |
|
16 | 15 | def _generate_sorted_tag_keys(all_items):
|
17 | 16 |
|
18 |
| - key_set = set() |
19 |
| - for item in all_items: |
20 |
| - for k, e in item['tags'].items(): |
21 |
| - key_set.add(k) |
22 |
| - |
| 17 | + key_set = set(itertools.chain(*[item['tags'].keys() for item in all_items])) |
23 | 18 | return sorted(key_set)
|
24 | 19 |
|
25 | 20 |
|
@@ -77,33 +72,23 @@ def build_from_items(items, filename, display_name, menu_html):
|
77 | 72 | if not item.get('thumbnail'):
|
78 | 73 | item['thumbnail'] = '/_static/images/ebp-logo.png'
|
79 | 74 | thumbnail = item['thumbnail']
|
80 |
| - |
81 |
| - tag_set = set() |
82 |
| - for k, e in item['tags'].items(): |
83 |
| - for t in e: |
84 |
| - tag_set.add(t) |
85 |
| - |
86 |
| - tag_list = sorted(tag_set) |
| 75 | + tag_list = sorted((itertools.chain(*item['tags'].values()))) |
87 | 76 | tags = [
|
88 | 77 | f'{{link-badge}}`"/pages/links/{tag.replace(" ", "-")}.html",{tag},cls=badge-primary badge-pill text-light`'
|
89 | 78 | for tag in tag_list
|
90 | 79 | ]
|
91 | 80 | tags = '\n'.join(tags)
|
92 | 81 |
|
93 | 82 | authors = [a.get('name', 'anonymous') for a in item['authors']]
|
| 83 | + authors_str = f"Created by: {', '.join(authors)}" |
94 | 84 |
|
95 |
| - if len(authors) == 1: |
96 |
| - authors_str = f'Created by: {authors[0]}' |
97 |
| - elif len(authors) == 2: |
98 |
| - authors_str = f'Created by: {authors[0]} and {authors[1]}' |
99 |
| - |
100 |
| - email = [a.get('email', None) for a in item['authors']][0] |
| 85 | + email = [a.get('email') for a in item['authors']][0] |
101 | 86 | email_str = '' if email is None else f'Email: {email}'
|
102 | 87 |
|
103 |
| - affiliation = [a.get('affiliation', None) for a in item['authors']][0] |
| 88 | + affiliation = [a.get('affiliation') for a in item['authors']][0] |
104 | 89 | affiliation_str = '' if affiliation is None else f'Affiliation: {affiliation}'
|
105 | 90 |
|
106 |
| - affiliation_url = [a.get('affiliation_url', None) for a in item['authors']][0] |
| 91 | + affiliation_url = [a.get('affiliation_url') for a in item['authors']][0] |
107 | 92 | affiliation_url_str = '' if affiliation_url is None else f'{affiliation} Site: <{affiliation_url}>'
|
108 | 93 |
|
109 | 94 | panels_body.append(
|
|
0 commit comments