-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
65 lines (55 loc) · 2.23 KB
/
build.py
File metadata and controls
65 lines (55 loc) · 2.23 KB
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
#!/usr/bin/env python3
import os
import yaml
from jinja2 import Environment, FileSystemLoader
# Setup Jinja2
env = Environment(loader=FileSystemLoader('templates'))
# Site context
site_context = {
'site_title': 'Orthodontic Software List',
'site_description': 'A list of medical software or devices designed for orthodontic data, focusing on interoperability levels.',
'build_date': '2025-01-18' # Update dynamically if needed
}
# Load software data
software_list = []
software_dir = '_software'
for filename in os.listdir(software_dir):
if filename.endswith('.md'):
with open(os.path.join(software_dir, filename), 'r') as f:
lines = f.readlines()
if lines[0].strip() == '---':
# Find end of frontmatter
yaml_start = 2
end_idx = lines[yaml_start:].index('---\n') + yaml_start
frontmatter_text = ''.join(lines[yaml_start:end_idx])
frontmatter = yaml.safe_load(frontmatter_text)
if frontmatter:
frontmatter['filename'] = filename.replace('.md', '.html')
software_list.append(frontmatter)
# Sort by product name
software_list.sort(key=lambda x: x['product'])
# Render style.css
template = env.get_template('style.css.j2')
output = template.render(**site_context)
os.makedirs('_site', exist_ok=True)
with open('_site/style.css', 'w') as f:
f.write(output)
# Render index.html
template = env.get_template('index.html.j2')
output = template.render(software_list=software_list, css_path="", index_path="", **site_context)
with open('_site/index.html', 'w') as f:
f.write(output)
# Render software pages
template = env.get_template('software.html.j2')
for software in software_list:
output = template.render(software=software, css_path="../", index_path="../", **site_context)
os.makedirs('_site/software', exist_ok=True)
with open(f'_site/software/{software["filename"]}', 'w') as f:
f.write(output)
# Render wiki.wiki
template = env.get_template('wiki.wiki.j2')
output = template.render(software_list=software_list, **site_context)
os.makedirs('output', exist_ok=True)
with open('output/wikipediaarticle.wiki', 'w') as f:
f.write(output)
print("Build complete!")