add stuff

This commit is contained in:
rgb 2025-02-20 21:28:08 +00:00
parent 3d25ee4774
commit 7dd1892a36
8 changed files with 167 additions and 1 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
dist/

View file

@ -1,3 +1,9 @@
# cl-website
colourlabs.net
the code for colourlabs.net
## build
```sh
python compile.py
```

36
assets/css/styles.css Normal file
View file

@ -0,0 +1,36 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #fff;
font-family: "Times New Roman";
}
.container {
padding: 17px;
line-height: 1.6;
}
.title {
text-decoration: underline;
font-size: 20px;
font-weight: bold;
}
.content {
padding-left: 10px;
}
ul {
padding-left: 30px;
}
.buttons {
display: flex;
flex-direction: row;
gap: 5px;
padding-top: 10px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

84
compile.py Normal file
View file

@ -0,0 +1,84 @@
# compiles the site
import markdown
import yaml
import re
import os
import datetime
import pytz
import socket
import shutil
from jinja2 import Template
def extract_metadata(md_content):
match = re.match(r"^---\n(.*?)\n---\n(.*)", md_content, re.DOTALL)
if match:
metadata, content = match.groups()
metadata_dict = yaml.safe_load(metadata)
return metadata_dict, content
return {}, md_content
def get_template_filename(metadata):
layout = metadata.get("layout", "default") # default to 'default'
return f"{layout}.html"
def convert_md_to_html(md_file, template):
with open(md_file, "r", encoding="utf-8") as f:
md_content = f.read()
# extract metadata
metadata, md_body = extract_metadata(md_content)
# convert md to html
html_content = markdown.markdown(md_body)
# render the template
rendered_html = template.render(
title=metadata.get("title", "untitled"),
content=html_content
)
tz = pytz.timezone('UTC')
build_date = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S %Z%z")
hostname = socket.gethostname()
rendered_html += f"\n<!-- built: {build_date} on machine '{hostname}' -->"
return rendered_html
def compile_site():
if not os.path.exists("dist/"):
os.makedirs("dist/")
for filename in os.listdir("site/"):
if filename.endswith(".md"):
md_path = os.path.join("site/", filename)
with open(md_path, "r", encoding="utf-8") as f:
md_content = f.read()
metadata, _ = extract_metadata(md_content)
template_filename = get_template_filename(metadata)
template_path = os.path.join("layouts/", template_filename)
with open(template_path, "r", encoding="utf-8") as f:
template = Template(f.read())
html_filename = filename.replace(".md", ".html")
html_path = os.path.join("dist/", html_filename)
html_content = convert_md_to_html(md_path, template)
with open(html_path, "w", encoding="utf-8") as f:
f.write(html_content)
print(f"converted {md_path} -> {html_path} using template {template_filename}")
assets_source = "assets"
assets_dest = "dist/" + "assets"
if os.path.exists(assets_source):
shutil.copytree(assets_source, assets_dest, dirs_exist_ok=True)
print(f"copied assets from {assets_source} to {assets_dest}")
else:
print(f"no assets folder found at {assets_source}")
if __name__ == "__main__":
compile_site()

17
layouts/default.html Normal file
View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<link rel="stylesheet" href="/assets/css/styles.css">
</head>
<body>
<div class="container">
<span class="title">colourlabs</span>
<div class="content">
{{ content }}
</div>
</div>
</body>
</html>

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
Jinja2==3.1.5
Markdown==3.7
pytz==2025.1
PyYAML==6.0.2

18
site/index.md Normal file
View file

@ -0,0 +1,18 @@
---
title: colourlabs
---
a place where we can dump stuff we like to play around with
#### services
- [git](https://git.colourlabs.net) - a forgejo instance, not being used for anything right now
- [minecraft server](https://mc.colourlabs.net) - our friends only minecraft server (version: 1.21.4)
#### blog
nothing to see here
<div class="buttons">
<img src="/assets/img/buttons/amd_powered.gif" alt="Powered by AMD" />
</div>