From 9cf9eb8e7e977ccd583cab0f12a798bb360b32e7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 10 Jan 2023 23:06:09 +0100 Subject: [PATCH] build/nav --- build.py | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 build.py diff --git a/build.py b/build.py new file mode 100755 index 0000000..f7a0e3f --- /dev/null +++ b/build.py @@ -0,0 +1,106 @@ +#! /usr/bin/env python3 + +import os +import subprocess + +SECTIONS = { + 'drift': 'Drift', + 'fs': 'FreeStyle', + 'k': 'K projects', + 'lol': 'LOL', + 'pf': 'Press Forward', + 'ta': 'Time Attack', + 'trial': 'Trial', +} + + +def card(name, web, raw): + return f'''\ +
+ +
+{name} +
+''' + + +def a(href, text, active=False): + html = ['{text}') + return str().join(html) + + +def nav(sections, active): + html = ['') + return str().join(html) + + +def body(sections): + html = [] + for section in sections.values(): + html.append(f'
') + html.append(section['content']) + html.append('
') + return str().join(html) + + +def html(body): + return f'''\ + + + + + +TrackMania vidz + + + + + +{body} + + + +''' + + +def main(): + file = os.path.realpath(__file__) + root = os.path.dirname(file) + raw_root = os.path.join(root, 'raw') + web_root = os.path.join(root, 'web') + _, categories, _ = next(os.walk(raw_root)) + sections = {} + for category in categories: + section = { + 'id': category, + 'label': SECTIONS.get(category, category), + } + content = [] + raw_category = os.path.join(raw_root, category) + for directory, directories, files in os.walk(raw_category): + for file in files: + relative = os.path.relpath(directory, raw_root) + name, _ = os.path.splitext(file) + raw_file = os.path.join('raw', relative, file) + web_file = os.path.join('web', relative, f'{name}.mp4') + content.append(card(name, web_file, raw_file)) + section['content'] = os.linesep.join(content) + sections[category] = section + for id, section in sections.items(): + section['content'] = nav(sections, id) + section['content'] + index = os.path.join(root, 'index.html') + with open(index, 'w') as i: + i.write(html(body(sections))) + + +if __name__ == '__main__': + main()