|
5 | 5 |
|
6 | 6 |
|
7 | 7 | class Box(): |
8 | | - def __init__(self, title): |
9 | | - self.title = title |
10 | | - self.content = None |
11 | | - self.links = [] |
12 | | - self.target = url_for('index') |
13 | | - self.img = None |
14 | | - |
15 | | - def add_link(self, title, href): |
16 | | - self.links.append((title, href)) |
| 8 | + def __init__(self, data): |
| 9 | + self.title = data["title"] |
| 10 | + self.img = url_for('static', filename=f'images/{data["image"]}.png') |
| 11 | + if self.title == "Announcements": |
| 12 | + # Dynamic content generated from knowl |
| 13 | + from lmfdb.knowledge.knowl import knowldb |
| 14 | + from lmfdb.knowledge.main import md |
| 15 | + max_entries = 3 |
| 16 | + content = [line.strip() for line in |
| 17 | + knowldb.get_knowl("content.announcements", ["content"])["content"].split("\n")] |
| 18 | + # Only keep lines that are part of an unordered list |
| 19 | + content = [line for line in content if line.startswith("* ") or line.startswith("- ") or line.startswith("+ ")] |
| 20 | + overflow = len(content) > max_entries |
| 21 | + content = content[:max_entries] |
| 22 | + content = "\n".join(content) |
| 23 | + if overflow: |
| 24 | + content += "\n* [More...](/announcements) (and [ongoing projects](/ongoing))" |
| 25 | + else: |
| 26 | + content += "\n* See also [ongoing projects](/ongoing)" |
| 27 | + self.content = md.convert(content) |
| 28 | + else: |
| 29 | + self.content = data["content"] |
17 | 30 |
|
18 | 31 | @cached_function |
19 | 32 | def load_boxes(): |
20 | | - boxes = [] |
21 | 33 | _curdir = os.path.dirname(os.path.abspath(__file__)) |
22 | 34 | with open(os.path.join(_curdir, "index_boxes.yaml")) as boxfile: |
23 | | - listboxes = yaml.load_all(boxfile, Loader=yaml.FullLoader) |
24 | | - for b in listboxes: |
25 | | - B = Box(b['title']) |
26 | | - B.content = b['content'] |
27 | | - if 'image' in b: |
28 | | - B.img = url_for('static', filename='images/'+b['image']+'.png') |
29 | | - for title, url in b['links']: |
30 | | - B.add_link(title, url) |
31 | | - boxes.append(B) |
32 | | - return boxes |
| 35 | + return [Box(b) for b in yaml.load_all(boxfile, Loader=yaml.FullLoader)] |
0 commit comments