-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-index-page.py
89 lines (73 loc) · 2.08 KB
/
gen-index-page.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
#!/usr/bin/env python3
import os
import sys
from datetime import datetime
def get_file_info(filename):
filename = f"./out/{filename}"
file_size = os.path.getsize(filename) / (1024 * 1024)
mod_time = os.path.getmtime(filename)
mod_date = datetime.fromtimestamp(mod_time).strftime("%Y-%m-%d %H:%M:%S")
return file_size, mod_date
HEAD = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index of /</title>
<style>
body { font-family: monospace; }
h1 { font-size: 1.5em; }
table { width: 100%; }
th, td { text-align: left; padding: 8px; }
th { background-color: #f2f2f2; }
a { text-decoration: none; color: #007bff; }
a:hover { text-decoration: underline; }
</style>
</head>
<body>
<h1>Index of /</h1>
<table>
<tr>
<th>Name</th>
<th>Last modified</th>
<th>Size</th>
<th>Description</th>
</tr>
<tr>
<td><a href="../">Parent Directory</a></td>
<td></td>
<td>-</td>
<td></td>
</tr>
"""
FOOTER = """
</table>
</br>
</br>
Note: All files are generated automatically via the GNU/Emacs Org-Mode export functions.
</br>
see: <a href="https://github.com/felixbd/thesis-template-in-org-mode/">https://github.com/felixbd/thesis-template-in-org-mode/</a>
</body>
</html>
"""
def main() -> None:
fen = sys.argv[1] # file export name
body = ""
for suffix in ["pdf", "txt", "html"]:
file_name = f"{fen}.{suffix}"
s, d = get_file_info(file_name)
body += f"""
<tr>
<td><a href="{file_name}">{file_name}</a></td>
<td>{d}</td>
<td>{s:.2f} MB</td>
<td>-</td>
</tr>
"""
index_content = HEAD + body + FOOTER
with open("./out/index.html", "w") as file:
file.write(index_content)
print("index.html generated successfully.")
if __name__ == "__main__":
main()