From 2dfb5fca4811c32d342d21ef5446a13ee18ca6fd Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 6 Feb 2021 00:35:11 +0100 Subject: [PATCH] Init static site generator --- .gitignore | 1 + generate.py | 78 ++++++++++++++++++++++++++++++++++++++++++++ templates/about.html | 50 ++++++++++++++++++++++++++++ templates/base.html | 54 ++++++++++++++++++++++++++++++ templates/index.html | 29 ++++++++++++++++ templates/tag.html | 21 ++++++++++++ templates/tags.html | 23 +++++++++++++ 7 files changed, 256 insertions(+) create mode 100644 .gitignore create mode 100755 generate.py create mode 100644 templates/about.html create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 templates/tag.html create mode 100644 templates/tags.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fcb152 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out diff --git a/generate.py b/generate.py new file mode 100755 index 0000000..0f0ba2e --- /dev/null +++ b/generate.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import sys + +source = Path(sys.argv[1]) +source_videos = source / "videos" + +out_tags = {} +out_videos = {} + +for video in source_videos.iterdir(): + if video.is_dir(): + slug = video.name + + if slug not in out_videos: + out_videos[slug] = { + "tags": [], + } + + tagfile = video / "tags" + if not tagfile.is_dir(): + with tagfile.open() as tags: + for tag in tags.readlines(): + tag = tag.strip() + out_videos[slug]["tags"].append(tag) + if tag not in out_tags: + out_tags[tag] = { + "videos": [], + "count_videos": None, + } + out_tags[tag]["videos"].append(slug) + +for tag in out_tags: + out_tags[tag]["count_videos"] = len(out_tags[tag]["videos"]) + +print(out_tags) + +from jinja2 import Environment, FileSystemLoader, select_autoescape +env = Environment( + loader=FileSystemLoader('./templates'), + autoescape=select_autoescape(['html']) +) + +from datetime import datetime +import random + +# Output +# Create output dir +out_dir = Path("./out") +out_dir.mkdir(parents=True, exist_ok=True) + +# Create main page +templ = env.get_template('index.html') +templ.stream(featured_tags=random.sample(list(out_tags), 6), out_tags=out_tags, out_videos=out_videos).dump(str((out_dir / "index.html").resolve())) + +# Create about pages +out_dir_about = out_dir / "about" +out_dir_about.mkdir(parents=True, exist_ok=True) + +# Create about page +templ = env.get_template('about.html') +templ.stream(last_update=datetime.now().strftime("%Y-%m-%d %H:%M:%S")).dump(str((out_dir_about / "index.html").resolve())) + + +# Create tag pages +out_dir_tag = out_dir / "tag" +out_dir_tag.mkdir(parents=True, exist_ok=True) + +# Create tag page +templ = env.get_template('tags.html') +templ.stream(sorted_tags=sorted(out_tags), out_tags=out_tags, out_videos=out_videos).dump(str((out_dir_tag / "index.html").resolve())) + +templ = env.get_template('tag.html') +for tag, tag_obj in out_tags.items(): + out_dir_tag_this = out_dir_tag / tag + out_dir_tag_this.mkdir(parents=True, exist_ok=True) + templ.stream(tag=tag, slugs=tag_obj["videos"], out_tags=out_tags, out_videos=out_videos).dump(str((out_dir_tag_this / "index.html").resolve())) diff --git a/templates/about.html b/templates/about.html new file mode 100644 index 0000000..1994392 --- /dev/null +++ b/templates/about.html @@ -0,0 +1,50 @@ +{% extends "base.html" %} + +{% block header %} +

About mediaCCCcollection

+{% endblock%} + +{% block content %} +
+

+
+
+

Meta

+
+
+
+
+
Software
+

You see here the mediaCCCcollectionUI.

+
+
+ GitHub +
Last update: {{ last_update }}
+
+
+
+
+
+
+
Development
+

mediaCCCcollection is developed by some people.

+
+
+ clerie +
+
+
+
+
+
+
Support
+

Help tagging all the videos!

+
+
+ GitHub +
+
+
+
+
+{% endblock %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..87d8a9f --- /dev/null +++ b/templates/base.html @@ -0,0 +1,54 @@ + + + + + + + + mediaCCCcollection + + + +
+
+ {% block header %} + {% endblock %} +
+
+
+
+ {% block content %}{% endblock %} +
+
+ + + + + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..0a0a402 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} + +{% block header %} +

mediaCCCcollection

+{% endblock %} + +{% block content %} +
+
+ {% for tag in featured_tags %} +
+
+
+
{{ tag }}
+
{{ out_tags[tag].count_videos }} Videos
+ More +
+
+
+ {% endfor %} +
+
+
+

mediaCCCcollection tries to curate videos of media.ccc.de by tagging them.

+
+
+ list of all tags +
+{% endblock %} diff --git a/templates/tag.html b/templates/tag.html new file mode 100644 index 0000000..fcf02aa --- /dev/null +++ b/templates/tag.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block header %} +

{{ tag }}

+{% endblock %} + +{% block content %} +
+ {% for slug in slugs %} +
+
+
{{ slug }}
+

+ {% for video_tag in out_videos[slug].tags %}{{ video_tag }}{% endfor %} +

+ watch +
+
+ {% endfor %} +
+{% endblock %} diff --git a/templates/tags.html b/templates/tags.html new file mode 100644 index 0000000..25672fd --- /dev/null +++ b/templates/tags.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} + +{% block header %} +

Tags

+{% endblock %} + +{% block content %} +
+
+ {% for tag in sorted_tags %} +
+
+
+
{{ tag }}
+
{{ out_tags[tag].count_videos }} Videos
+ More +
+
+
+ {% endfor %} +
+
+{% endblock %}