Hello there!
+General info about the page goes here
+ +diff --git a/main.py b/main.py
index cd9ac48..ff38978 100644
--- a/main.py
+++ b/main.py
@@ -1,5 +1,58 @@
+from jinja2 import Environment, FileSystemLoader
+from itertools import chain
+from pathlib import Path
+import mimetypes
+
+
+MEDIA_FOLDER = "/home/thibaud/Vidéos/Programmation/"
+OUTPUT_DIR = "./out"
+
+
+def find(name: str, path: Path) -> Path:
+ for file in path.glob("*.*"):
+ if name in file.name:
+ return file
+
+
+def generate_index(folder: Path, output: Path, env: Environment):
+ template = env.get_template("main.tpl")
+ file = output.joinpath(f"{folder.stem}.html")
+ with open(file, "w") as outfile:
+ articles = []
+ for file in chain(folder.glob("*.mkv"), folder.glob("*.mp4")):
+ articles.append(
+ env.get_template("video.tpl").render(
+ staticdir="/static/",
+ title=file.stem,
+ src="/" + str(file.relative_to(Path(MEDIA_FOLDER).parent)),
+ mime=mimetypes.guess_type(file),
+ )
+ )
+
+ outfile.writelines(template.render(content="\n".join(articles)))
+
+
def main():
- pass
+ out = Path(OUTPUT_DIR)
+ with open(out.joinpath("index.html"), "w") as outfile:
+ env = Environment(loader=FileSystemLoader("templates"))
+ template = env.get_template("main.tpl")
+
+ articles = []
+ for folder in (x for x in Path(MEDIA_FOLDER).iterdir() if x.is_dir()):
+ # Main index
+ thumbnail = find("thumbnail.png", folder)
+ articles.append(
+ env.get_template("folder.tpl").render(
+ staticdir="/static/",
+ title=folder.stem,
+ src=str(thumbnail),
+ ref=str(folder) + '.html'
+ )
+ )
+ generate_index(folder, out, env)
+
+ outfile.writelines(template.render(content="\n".join(articles)))
if __name__ == "__main__":
diff --git a/templates/folder.tpl b/templates/folder.tpl
new file mode 100644
index 0000000..8cd251d
--- /dev/null
+++ b/templates/folder.tpl
@@ -0,0 +1,6 @@
+{{ title }}
+
+
+
+
General info about the page goes here
+ +