Init static site generator

This commit is contained in:
clerie 2021-02-06 00:35:11 +01:00
parent f83f3acb49
commit 2dfb5fca48
7 changed files with 256 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
out

78
generate.py Executable file
View File

@ -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()))

50
templates/about.html Normal file
View File

@ -0,0 +1,50 @@
{% extends "base.html" %}
{% block header %}
<h1 class="display-4">About mediaCCCcollection</h1>
{% endblock%}
{% block content %}
<section>
<p></p>
</section>
<section>
<h2>Meta</h2>
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Software</h5>
<p class="card-text">You see here the mediaCCCcollectionUI.</p>
</div>
<div class="list-group list-group-flush">
<a href="https://github.com/clerie/" class="list-group-item">GitHub</a>
<div class="list-group-item">Last update: {{ last_update }}</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Development</h5>
<p class="card-text">mediaCCCcollection is developed by some people.</p>
</div>
<div class="list-group list-group-flush">
<a href="https://clerie.de/" class="list-group-item">clerie</a>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Support</h5>
<p class="card-text">Help tagging all the videos!</p>
</div>
<div class="list-group list-group-flush">
<a href="https://github.com/clerie/mediaccccollection" class="list-group-item">GitHub</a>
</div>
</div>
</div>
</div>
</section>
{% endblock %}

54
templates/base.html Normal file
View File

@ -0,0 +1,54 @@
<!doctype html>
<html lang="de">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://wetter.clerie.de/static/bundle/bundle.css">
<title>mediaCCCcollection</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container">
<a class="navbar-brand" href="/">mediaCCCcollection</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggler">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="/tag/">Tags</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about/">About</a>
</li>
</ul>
</div>
</div>
</nav>
<header>
<div class="container">
{% block header %}
{% endblock %}
</div>
</header>
<main>
<div class="container">
{% block content %}{% endblock %}
</div>
</main>
<footer>
<div class="container">
<a href="/about/">Über</a>
<a href="/station/">Stationen</a>
<a href="https://blog.clerie.de/impressum" target="_blank">Imprint</a>
<a href="https://blog.clerie.de/datenschutz" target="_blank">Privacy</a>
<a href="https://github.com/clerie/wetter" target="_blank">Sourcecode</a>
</div>
</footer>
<!-- Optional JavaScript -->
<script src="https://wetter.clerie.de/static/bundle/wetter.js"></script>
</body>
</html>

29
templates/index.html Normal file
View File

@ -0,0 +1,29 @@
{% extends 'base.html' %}
{% block header %}
<h1 class="display-1">mediaCCCcollection</h1>
{% endblock %}
{% block content %}
<section>
<div class="row">
{% for tag in featured_tags %}
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ tag }}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ out_tags[tag].count_videos }} Videos</h6>
<a href="/tag/{{ tag }}" class="btn btn-primary card-link">More</a>
</div>
</div>
</div>
{% endfor %}
</div>
</section>
<section>
<p>mediaCCCcollection tries to curate videos of <a href="https://media.ccc.de/">media.ccc.de</a> by tagging them.</p>
</section>
<section>
<a href="/tag/" class="btn btn-lg btn-outline-primary btn-block">list of all tags</a>
</section>
{% endblock %}

21
templates/tag.html Normal file
View File

@ -0,0 +1,21 @@
{% extends 'base.html' %}
{% block header %}
<h1 class="display-2">{{ tag }}</h1>
{% endblock %}
{% block content %}
<section>
{% for slug in slugs %}
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ slug }}</h5>
<p>
{% for video_tag in out_videos[slug].tags %}<a href="/tag/{{ video_tag }}/" class="badge badge-light">{{ video_tag }}</a>{% endfor %}
</p>
<a href="https://media.ccc.de/v/{{ slug }}" class="btn btn-primary card-link">watch</a>
</div>
</div>
{% endfor %}
</section>
{% endblock %}

23
templates/tags.html Normal file
View File

@ -0,0 +1,23 @@
{% extends 'base.html' %}
{% block header %}
<h1 class="display-2">Tags</h1>
{% endblock %}
{% block content %}
<section>
<div class="row">
{% for tag in sorted_tags %}
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ tag }}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ out_tags[tag].count_videos }} Videos</h6>
<a href="/tag/{{ tag }}" class="btn btn-primary card-link">More</a>
</div>
</div>
</div>
{% endfor %}
</div>
</section>
{% endblock %}