-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_docs.py
53 lines (42 loc) · 1.24 KB
/
update_docs.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
from pathlib import Path
years = sorted([y for y in Path("src").iterdir() if y.is_dir()], reverse=True)
with open("docs/index.md", "w", encoding="utf-8") as f:
star = ' <img src="https://cdn3.iconfinder.com/data/icons/fatcow/32/asterisk_yellow.png" alt="logo" height="32">'
stars = "\n".join([star] * 5)
items = "\n".join([f"- [{y.stem}]({y.stem}.md)" for y in years])
text = f"""
<div align="center">
{stars}
</div>
# Advent of Code
Solutions to [Advent of Code](https://adventofcode.com/)
{items}
"""
f.write(text.strip())
for y in years:
days = {}
for d in list(y.glob("*.py")):
name = d.stem.split("_")[0]
if name not in days:
days[name] = [d]
else:
days[name].append(d)
text = f"""
# Advent of Code {y.stem}
"""
for d in sorted(days):
parts = [
f"""
=== "{p.stem.split('_')[-1].capitalize().replace("Part","Part ")}"
```py linenums="1"
--8<-- "{str(p.as_posix())}"
```
"""
for p in sorted(days[d])
]
text += f"""
??? success "{d.capitalize().replace("Day","Day ")}"
{''.join(parts)}
""".lstrip()
with open(f"docs/{y.stem}.md", "w", encoding="utf-8") as f:
f.write(text.strip())