From ed79ab84884979fce095444423f746c366501377 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 2 Oct 2021 15:37:51 +0100 Subject: added all data --- build.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'build.py') diff --git a/build.py b/build.py index e922ac9..5059d21 100644 --- a/build.py +++ b/build.py @@ -82,6 +82,8 @@ def make(): pages = listPages() + pages = sorted(pages, key=lambda p: p["timestamp"]) + summary_templ = getTemplateHTML("summary.html") summariesHTML = getTemplateHTML("about.html") + "\n
\n"+ "\n
\n".join( @@ -98,6 +100,7 @@ def make(): entry_templ = getTemplateHTML("page.html") + for page in pages: with open(os.path.join(dist, page["url"]), "w") as entry: entry.write( @@ -142,7 +145,7 @@ def get_repos(): repos = [] if os.path.exists("git_repos.txt"): with open("git_repos.txt", "r") as file: - repos = file.read().split("\n")[:-1] + repos = [l for l in file.readlines() if l.startswith("http")] return repos def list_files(path): @@ -157,56 +160,97 @@ def list_files(path): return files +def linkify_path(path): + output = [] + full = "/" + for s in path.split("/"): + full += s + "/" + output.append(f"{s}") + return "/" + "/".join(output) + + + def format_file(page_templ, content, v): return page_templ.replace("%title%", v["name"])\ .replace("%up%", v["above"])\ - .replace("%filename%", v["filename"])\ + .replace("%filename%", linkify_path(v["filename"]))\ .replace("%commit%", str(v["commit"]))\ + .replace("%url%", str(v["url"]))\ .replace("%content%", content) -def traverse_repo(path, name, commit): +def traverse_repo(path, name, commit, url): page_templ = getTemplateHTML("page.html") page_templ = page_templ.replace("%content%", getTemplateHTML("file.html")) + date = time.strftime(date_format, time.localtime()) + footer = f"

This repo has been compiled for web view on {date} and may not be the latest version

" + for root, dirs, files in os.walk(path): + filename = "/".join(root.split("/")[1:]) index_content = "
" + + readme = os.path.join(root, "README.md") + if os.path.exists(readme): + with open(readme) as file: + readme_content = markdown.markdown(file.read()) + #massive hack + readme_content = readme_content.replace("\"/", "\"/" + filename + "/") + + index_content += readme_content - index_content += "" + index_content += "
" + index_content += footer index_content = format_file(page_templ, index_content, { "name": name, "commit": commit, - "filename": "/".join(root.split("/")[1:]), + "url": url, + "filename": filename, "above": "/".join(root.split("/")[1:-1]), }) @@ -236,7 +280,7 @@ def create_repos(): commit = command.stdout.decode() - traverse_repo(os.path.join(git_path, name), name, commit) + traverse_repo(os.path.join(git_path, name), name, commit, repo) make() create_repos() -- cgit v1.2.1