From 20d20929290e57316bef3625b18d4ee37c0cf9a7 Mon Sep 17 00:00:00 2001 From: Ashik K Date: Sat, 8 Apr 2023 10:42:57 +0200 Subject: [PATCH] fix the links --- genstatic.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/genstatic.py b/genstatic.py index df53c23..66ae7ab 100644 --- a/genstatic.py +++ b/genstatic.py @@ -12,17 +12,27 @@ if len(sys.argv) != 2: # set the directory from the command line argument dir = sys.argv[1] -# create a file named index.html -outfile = open("index.html", "w") +# create a file named index.html inside the directory that was passed as a command line argument +outfile = open(dir + "/index.html", "w") #write a tag to the file outfile.write("") # insert links to every html file in the # 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"): + # skip index.html + if file == "index.html": + continue # write the link to the html file - outfile.write("" + file + "
") + # extract the text inside the title tag in the html file as a string + title = Path(dir + "/" + file).read_text().split("")[1].split("")[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("" + title + "
") + # close the file #write a tag to the file outfile.write("") -outfile.close \ No newline at end of file +outfile.close