-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_indexes.py
47 lines (42 loc) · 1.75 KB
/
generate_indexes.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
from yattag import Doc
import os
def generate_index(dir):
index_file = os.path.join(dir, 'index.html')
title = dir.split('/')[-1]
doc, tag, text, line = Doc().ttl()
doc.asis('<!DOCTYPE html>')
with tag('html'):
doc.attr(title=title)
with tag('head'):
doc.stag('meta', charset='utf-8')
doc.stag('meta', name="viewport", content="width=device-width, initial-scale=1")
doc.stag('link', rel='stylesheet', href='https://unpkg.com/@picocss/pico@latest/css/pico.min.css')
with tag('title'):
text(title)
with tag('body'):
with tag('main', klass="container"):
with tag('h1'):
text(f"{title}")
with tag('p'):
with tag('a', href='..'):
text('..')
directories = sorted([d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))])
files = sorted([d for d in os.listdir(dir) if os.path.isfile(os.path.join(dir, d))], reverse=True)
for item in directories + files:
if (item == 'index.html'):
continue
if (item == 'snapshot.atom'):
continue
if (item == 'meta.json'):
continue
if (item.startswith('.')):
continue
with tag('p'):
with tag('a', href=item):
text(item)
with open(index_file, 'w') as f:
f.write(doc.getvalue())
for item in directories:
generate_index(os.path.join(dir, item))
if __name__ == "__main__":
generate_index('exports')