summaryrefslogtreecommitdiff
path: root/build.py
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2021-10-02 15:37:51 +0100
committerdavidovski <david@davidovski.xyz>2021-10-02 15:37:51 +0100
commited79ab84884979fce095444423f746c366501377 (patch)
tree0f467a3f3a2a997dc3cd808538a381be0a7733d9 /build.py
parenteed4ab6ebf07a696ed13bfeb70ccd73784208748 (diff)
added all data
Diffstat (limited to 'build.py')
-rw-r--r--build.py72
1 files changed, 58 insertions, 14 deletions
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<hr>\n"+ "\n<hr>\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"<a href='{full}'>{s}</a>")
+ 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"<p class='small'>This repo has been compiled for web view on <b>{date}</b> and may not be the latest version</p>"
+
for root, dirs, files in os.walk(path):
+ filename = "/".join(root.split("/")[1:])
index_content = "<ul>"
+ index_content += f"<a href='../'><li>../</li></a>"
for d in dirs:
- if not d.startswith("."):
+ if d.startswith("."):
+ shutil.rmtree(os.path.join(root, d))
+ else:
index_content += f"<a href='{d}'><li>{d}/</li></a>"
- for f in files:
- if not f.startswith("."):
- index_content += f"<a href='{f}.html'><li>{f}</li></a>"
- f = os.path.join(root,f)
+ for file_name in files:
+ if file_name.startswith("."):
+ os.remove(f)
+ else:
+ f = os.path.join(root, file_name)
try:
- print(f"editing {f}...")
with open(f, "r") as file:
content = file.read()
if f.endswith(".md"):
content = markdown.markdown(content)
+ content = content.replace("\"/", "\"/" + filename + "/")
+ else:
+ content = "<p><pre><code>" + escape(content) + "</code></p></pre>"
- content = format_file(page_templ, "<p><pre><code>" + escape(content) + "</code></p></pre>", {
+ content += footer
+ content = format_file(page_templ, content, {
"name": name,
"commit": commit,
+ "url": url,
"filename": "/".join(f.split("/")[1:]),
"above": "/".join(f.split("/")[1:-1]),
})
with open(f + ".html", "w") as file:
file.write(content)
+
+ if file_name != "README.md":
+ os.remove(f)
+
+ index_content += f"<a href='{file_name}.html'><li>{file_name}</li></a>"
except UnicodeDecodeError:
- pass
+ index_content += f"<a href='{file_name}'><li>{file_name}</li></a>"
+
+ index_content += "</ul><hr>"
+
+ 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 += "</ul>"
+ index_content += "<hr>"
+ 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()