diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7773828 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/ \ No newline at end of file diff --git a/README.md b/README.md index 940a28a..cf2c994 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # cl-website -colourlabs.net \ No newline at end of file +the code for colourlabs.net + +## build + +```sh +python compile.py +``` \ No newline at end of file diff --git a/assets/css/styles.css b/assets/css/styles.css new file mode 100644 index 0000000..b5bc362 --- /dev/null +++ b/assets/css/styles.css @@ -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; +} \ No newline at end of file diff --git a/assets/img/buttons/amd_powered.gif b/assets/img/buttons/amd_powered.gif new file mode 100644 index 0000000..ecd0402 Binary files /dev/null and b/assets/img/buttons/amd_powered.gif differ diff --git a/compile.py b/compile.py new file mode 100644 index 0000000..c2acfe1 --- /dev/null +++ b/compile.py @@ -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" + + 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() \ No newline at end of file diff --git a/layouts/default.html b/layouts/default.html new file mode 100644 index 0000000..ec8380c --- /dev/null +++ b/layouts/default.html @@ -0,0 +1,17 @@ + + +
+ + +