-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmirror_render_help_pages.py
88 lines (72 loc) · 2.34 KB
/
mirror_render_help_pages.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
import glob
import os
from string import Template
HEADER = """
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="/mirror.css" media="screen" />
<title>广东工业大学开源镜像站</title>
</head>
<body class="fade-in">
<header>
<h1><img style="vertical-align: middle;" src="/GDUT_Logo.png" width="40" height="40"/> 广东工业大学开源镜像站</h1>
</header>
<div class="container">
<div class="col-25">
<ul class="nav">
"""
NAVIGATION_TEMPLATE = Template("""
<li class="nav-item">
<a href="/help/${mirror}.html" class="nav-link ${selected}">${mirror}</a>
</li>
""")
FOOTER = Template("""
</ul>
</div>
<div class="col-75">
<h2>${mirror}镜像使用帮助</h2>
${html}
</div>
</div>
<div id="footer">
🏠<a target="_blank" href="http://www.gdut.edu.cn/">广东工业大学首页</a>
|
❓<a target="_blank" href="about.html">关于我们</a>
|
📮<a href="mailto:[email protected]">联系我们</a>
|
🟢<a target="_blank" href="status.html">当前状态</a>
</div>
<script type="text/javascript" src="/mirror.js"></script>
</body>
</html>
""")
mirror_list = sorted(glob.glob('/mnt/mirror/*'))
ignore_dir = ['static', 'font', 'help']
if not os.path.exists('/mnt/mirror/help'):
os.makedirs('/mnt/mirror/help') # 创建文件夹
mirror_names = []
for mirror in mirror_list:
if os.path.isdir(mirror):
mirror_name = mirror.split('/')[-1]
# 判断目录是否要忽略
if mirror_name in ignore_dir:
continue
mirror_names.append(mirror_name)
for mirror in mirror_names:
html = HEADER
for m in mirror_names:
if m == mirror:
selected = "nav-link-selected"
else:
selected = ""
html += NAVIGATION_TEMPLATE.substitute(mirror=m, selected=selected)
try:
with open(f'help_pages_template/{mirror}.html', 'r') as f:
html += FOOTER.substitute(mirror=mirror, html=f.read())
except FileNotFoundError:
html += FOOTER.substitute(mirror=mirror, html="<p>该镜像的帮助文档正在编写中……</p>")
with open(f'/mnt/mirror/help/{mirror}.html', 'w') as f:
f.write(html)