fix the links
This commit is contained in:
parent
35978aa910
commit
01d0ba8d7a
20
genstatic.py
20
genstatic.py
|
@ -12,17 +12,27 @@ if len(sys.argv) != 2:
|
||||||
|
|
||||||
# set the directory from the command line argument
|
# set the directory from the command line argument
|
||||||
dir = sys.argv[1]
|
dir = sys.argv[1]
|
||||||
# create a file named index.html
|
# create a file named index.html inside the directory that was passed as a command line argument
|
||||||
outfile = open("index.html", "w")
|
outfile = open(dir + "/index.html", "w")
|
||||||
#write a <html> tag to the file
|
#write a <html> tag to the file
|
||||||
outfile.write("<html>")
|
outfile.write("<html>")
|
||||||
# insert links to every html file in the
|
# insert links to every html file in the
|
||||||
# directory that was passed as a command line argument
|
# directory that was passed as a command line argument
|
||||||
for file in os.listdir(dir):
|
# Files that start with "page" should be the first ones in the list
|
||||||
|
|
||||||
|
for file in sorted(os.listdir(dir)):
|
||||||
if file.endswith(".html"):
|
if file.endswith(".html"):
|
||||||
|
# skip index.html
|
||||||
|
if file == "index.html":
|
||||||
|
continue
|
||||||
# write the link to the html file
|
# write the link to the html file
|
||||||
outfile.write("<a href=" + file + ">" + file + "</a><br>")
|
# extract the text inside the title tag in the html file as a string
|
||||||
|
title = Path(dir + "/" + file).read_text().split("<title>")[1].split("</title>")[0]
|
||||||
|
# write the link to the html file. The link text should be the text inside the title tag
|
||||||
|
# and the link should be relative to the index.html file (same directory)
|
||||||
|
outfile.write("<a href=\"" + file + "\">" + title + "</a><br>")
|
||||||
|
|
||||||
# close the file
|
# close the file
|
||||||
#write a </html> tag to the file
|
#write a </html> tag to the file
|
||||||
outfile.write("</html>")
|
outfile.write("</html>")
|
||||||
outfile.close
|
outfile.close
|
||||||
|
|
Loading…
Reference in New Issue