-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit_site.py
168 lines (133 loc) · 7.65 KB
/
init_site.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import yaml
from lxml import etree, html
def generate_html_from_yaml(oss_projects_file, cs_groups_file, html_file, output_file):
# Parse the existing HTML file
with open(html_file, "r", encoding="utf-8") as f:
tree = html.parse(f)
root = tree.getroot()
# Find the <div> element with id "project-list"
project_list = root.find(".//div[@id='project-list']")
# Parse the YAML data of projects
with open(oss_projects_file, "r") as f:
projects = yaml.load(f, Loader=yaml.Loader)
# Parse the YAML data of cs groups
with open(cs_groups_file, "r") as f:
cs_groups = yaml.load(f, Loader=yaml.Loader)
licences = set()
groups = set()
# sort projects by involvement
projects_with_involvement = []
projects_without_involvement = []
for project in projects:
involved = project.get("involved", "")
# Assume N/A is involved
if involved == False:
projects_without_involvement.append(project)
else:
projects_with_involvement.append(project)
# Sort projects by name
projects_with_involvement = sorted(projects_with_involvement, key=lambda x: x.get("name").lower())
projects_without_involvement = sorted(projects_without_involvement, key=lambda x: x.get("name").lower())
projects = projects_with_involvement + projects_without_involvement
no_longer_involved_start = len(projects_with_involvement)
# Generate HTML items for each project
for i, project in enumerate(projects):
if i == no_longer_involved_start:
no_longer_involved = etree.Element("h2", attrib={"class": "no-longer-involved-header"}, id="no-longer-involved")
no_longer_involved.text = "Projects where the research group is no longer involved"
project_list.append(no_longer_involved)
project_name = project.get("name")
if not project_name:
continue
# Create project div
project_item = etree.Element("div", id=str(i), attrib={"class": "project"})
project_main = etree.SubElement(project_item, "div", attrib={"class": "project-main"})
project_main_left = etree.SubElement(project_main, "div", attrib={"class": "project-main-left"})
involved = project.get("involved", "")
if involved == False:
not_involved = etree.SubElement(project_main_left, "span", attrib={"class": "not-involved"})
not_involved.text = "no longer involved"
# CS group information
cs_group_handles = project.get("groups")
if cs_group_handles:
for group_handle in cs_group_handles:
group = None
for cs_group in cs_groups:
if cs_group.get("handle") == group_handle:
group = cs_group
break
if group:
project_group = etree.SubElement(project_main_left, "div", attrib={"class": "project-chair"})
group_name = group.get("name")
groups.add(group_name)
group_link = group.get("website")
chair = etree.SubElement(project_group, "a", attrib={"class": "chair"})
chair_name_span = etree.SubElement(chair, "span", attrib={"class": "chair-name"})
chair_name_span.text = group_name
if group_link:
chair.set("href", group_link)
chair.set("target", "_blank")
chair.set("title", group_link)
etree.SubElement(chair, "img", attrib={"class": "chair-link-img"}, src="images/external-link-svgrepo-com-grey.svg", style="height: 16px")
# Project name and more info
project_row = etree.SubElement(project_main_left, "div", attrib={"class": "project-row", "onclick": f"popUp({i})"})
project_name_div = etree.SubElement(project_row, "div", attrib={"class": "project-name"}, id=f"project-name-{i}")
project_name_div.text = project_name
project_more_info_text = project.get("description")
if project_more_info_text:
project_more_info_popup = etree.SubElement(project_main_left, "div", attrib={"class": "project-more-info-popup"}, id=f"more-info-{i}", title = project_more_info_text)
project_more_info_popup.text = project_more_info_text
# Project tags
project_tags = etree.SubElement(project_main_left, "div", attrib={"class": "project-tags"})
roles = {"Founder": "founder",
"Maintainer": "maintainer",
"Contributor": "contributor"}
for role, key in roles.items():
if project.get(key) == True:
tag = etree.SubElement(project_tags, "span", attrib={"class": f"tag {role.lower()}"})
tag.text = role
project_main.append(project_main_left)
# Project image
img_src = f"images/projects/{project['logo']}" if project.get("logo") else ""
if img_src:
img = etree.SubElement(project_main, "img", src=img_src, attrib={"class": "project-logo"})
project_item.append(project_main)
# Link footer
link_footer = etree.SubElement(project_item, "div", attrib={"class": "link-footer"})
link_footer_left = etree.SubElement(link_footer, "div", attrib={"class": "link-footer-left"})
project_site = project.get("website")
if project_site:
link_item = etree.SubElement(link_footer_left, "a", attrib={"class": "link-item"}, title=project_site, href=project_site, target="_blank")
link_item_text = etree.SubElement(link_item, "span", attrib={"class": "link-item-text"})
link_item_text.text = "Project Site"
link_item_icon = etree.SubElement(link_item, "img", src="images/external-link-svgrepo-com-white.svg", style="height: 20px")
repository = project.get("repository")
if repository:
link_item = etree.SubElement(link_footer_left, "a", attrib={"class": "link-item"}, title=repository, href=repository, target="_blank")
link_item_text = etree.SubElement(link_item, "span", attrib={"class": "link-item-text"})
link_item_text.text = "Code"
link_item_icon = etree.SubElement(link_item, "img", src="images/external-link-svgrepo-com-white.svg", style="height: 20px")
# License
license = project.get("license")
if license:
licences.add(license)
license_item = etree.SubElement(link_footer, "div", attrib={"class": "license-item"}, title=license, id=f"license-{i}")
license_item.text = license
project_list.append(project_item)
# Add chair and license filters
chair_filter = root.find(".//select[@id='chair']")
if chair_filter is not None:
for chair in sorted(groups):
option = etree.SubElement(chair_filter, "option", value=chair)
option.text = chair
license_filter = root.find(".//select[@id='license']")
if license_filter is not None:
for license in sorted(licences):
option = etree.SubElement(license_filter, "option", value=license)
option.text = license
etree.indent(root)
# Write the modified HTML back to a file
with open(output_file, "w", encoding="utf-8") as f:
f.write("<!DOCTYPE html>\n")
f.write(etree.tostring(root, pretty_print=True, encoding="unicode", method='html'))
generate_html_from_yaml("oss-projects.yaml", "cs-groups.yaml", "website/base.html", "website/index.html")