-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreloader.py
More file actions
65 lines (49 loc) · 1.53 KB
/
reloader.py
File metadata and controls
65 lines (49 loc) · 1.53 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
import sys
import os
from livereload import Server
md_file = ""
html_file = ""
footer_file = "resources/footer_dev.html"
def md_to_html():
global md_file
global html_file
global footer_file
# Read the contents of the markdown file
with open(md_file, "r", encoding="utf-8") as f:
content = f.read()
with open("resources/header.html", "r") as f:
header = f.read()
with open(footer_file, "r") as f:
footer = f.read()
content = f"{header}\n\n{content}\n\n{footer}"
# Create the new HTML file
html_file = md_file.replace(".md", ".html")
with open(html_file, "w", encoding="utf-8") as f:
f.write(content)
def start_server():
global md_file
global html_file
md_to_html()
server = Server()
server.watch(md_file, md_to_html)
server.watch(html_file)
server.serve(default_filename=html_file, root=f"./", liveport=35729, restart_delay=0)
def main():
global md_file
if not md_file.endswith(".md"):
print("Error: The input file must be a markdown (.md) file.")
return
if not os.path.isfile(md_file):
print(f"Error: The file '{md_file}' does not exist.")
return
start_server()
if __name__ == "__main__":
if len(sys.argv) == 2 or len(sys.argv) == 3:
md_file = sys.argv[1]
if len(sys.argv) == 3 and sys.argv[2] == "release":
footer_file = "resources/footer.html"
md_to_html()
else:
main()
else:
print("Usage: python md_to_html.py <file.md>")