summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.py72
-rw-r--r--git_repos.txt7
-rw-r--r--src/git_compile.md15
-rwxr-xr-xsync.sh2
-rw-r--r--templates/file.html4
-rw-r--r--templates/page.html2
6 files changed, 84 insertions, 18 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()
diff --git a/git_repos.txt b/git_repos.txt
index 04c0368..dd2848f 100644
--- a/git_repos.txt
+++ b/git_repos.txt
@@ -1 +1,8 @@
https://git.davidovski.xyz/davidovski.git
+https://git.davidovski.xyz/psibuild.git
+https://github.com/davidovski/glsl-mandelbrot.git
+https://github.com/davidovski/dungeon-generator.git
+https://github.com/davidovski/chatroom.git
+https://github.com/davidovski/kblg.git
+https://github.com/davidovski/asteriods.git
+https://github.com/davidovski/anyscroll.git
diff --git a/src/git_compile.md b/src/git_compile.md
new file mode 100644
index 0000000..05176c0
--- /dev/null
+++ b/src/git_compile.md
@@ -0,0 +1,15 @@
+# Compiling files in a git repo
+
+So I decided to improve the way that that you can access some of the repos that I am hosting on this server, including the code that I use to compile the site itself. I quickly hacked together a bit of code in my existing [build.py](https://davidovski.xyz/git/davidovski/build.py.html) to clone a list of repos and go through and generate a html pages for each of the files in the repo.
+
+...
+
+Although this means that this is only a static view of the repo at any time (needing me to rebuild the site for it to update) I can easily add any git repo to be built into my site, so as you may see, I have added a few repos from my github as well.
+
+I tried using cgit, but it just didn't provide exactly what I wanted and I wasn't in the mood to try configuring it to my liking, so I opted for this approach instead.
+
+A way that I can improve it is to serve a http server that dynamically updates the repositories when new commits are added, which would probably be a better solution; but this works.. for now.
+
+If you want to view all of the repos that I've listed so far, click the link at the top of the page. (sorry that the index is still the default nginx autoindex, I will change that at some point), and feel free to check out how I did it in [build.py](https://davidovski.xyz/git/davidovski/build.py.html), though Im warning you, its probably some of the hackiest code i've put together.
+
+Tutorial on how to host your own git repos on your server and allow people to clone them with https may be coming soon
diff --git a/sync.sh b/sync.sh
index 11a9f8d..25107f9 100755
--- a/sync.sh
+++ b/sync.sh
@@ -1,7 +1,7 @@
#!/bin/bash
python build.py
-rsync -Lta --no-perms --no-owner --no-group --delete --exclude=sync.sh -vz -e ssh ./html/ cheetah:/srv/www/davidovski/html
+rsync -Lta --no-perms --no-owner --no-group --delete --exclude=sync.sh -z -e ssh ./html/ cheetah:/srv/www/davidovski/html
ssh -t cheetah "ln -s /srv/shared/site/* /srv/www/davidovski/html/"
diff --git a/templates/file.html b/templates/file.html
index 6171875..19048c3 100644
--- a/templates/file.html
+++ b/templates/file.html
@@ -1,7 +1,7 @@
<h1>%filename%</h1>
-<p><a href="../">../</a></p>
-
<p><code>%commit%</code></p>
%content%
+
+<p>Clone this repo: <code>git clone %url%</code><p>
diff --git a/templates/page.html b/templates/page.html
index 6537bc6..18c74be 100644
--- a/templates/page.html
+++ b/templates/page.html
@@ -12,7 +12,7 @@
<a href="https://davidovski.xyz/"<h1 class="title">davidovski.xyz</h1></a>
<hr>
<div class="links">
- <a href="https://github.com/davidovski">git</a>
+ <a href="https://davidovski.xyz/git">git</a>
|
<a href="https://osu.ppy.sh/users/11140827">osu</a>
|