diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-02-10 15:01:27 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-02-10 15:01:27 +0100 |
| commit | 98671c933d4877465fa343855e095e3e8e126dea (patch) | |
| tree | 2f3e964a6a6dca4d7c59ad0d7009b729d45fbb53 /generate-gallery.py | |
| parent | 6a1bb5759062c5e62f50af2e534200d40cf42312 (diff) | |
| download | scratch-gallery-98671c933d4877465fa343855e095e3e8e126dea.tar.gz scratch-gallery-98671c933d4877465fa343855e095e3e8e126dea.zip | |
use german place holders and support multiple slides
Diffstat (limited to 'generate-gallery.py')
| -rwxr-xr-x | generate-gallery.py | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/generate-gallery.py b/generate-gallery.py index 5049d84..773261f 100755 --- a/generate-gallery.py +++ b/generate-gallery.py @@ -61,19 +61,24 @@ def load_projects(root: str) -> dict: with open(parent / 'meta.toml', 'rb') as meta_file: game = tomllib.load(meta_file) - if 'name' not in game: - game['name'] = 'Project' - - if 'authors' not in game: - game['authors'] = ['anonym'] + if 'Name' not in game: + if 'Datei' in game: + game['Name'] = pathlib.Path(game['Datei']).stem + else: + game['Name'] = 'Project' + + if 'Team' not in game: + game['Team'] = ['anonym'] else: - game['authors'] = ', '.join(game['authors']) + game['Team'] = ', '.join(game['Team']) - if 'path' not in game: - game['path'] = parent.relative_to(root) + if 'Pfad' not in game: + game['Pfad'] = str(parent.relative_to(root)) - if 'license' not in game: - game['license'] = 'Alle Rechte vorbehalten' + if 'Lizenz' not in game: + game['Lizenz'] = 'Alle Rechte vorbehalten' + elif game['Lizenz'].startswith('CC') and game['Datei'].endswith('sb3'): + game['Download'] = game['Datei'] nested_set(projects, parent.parts[1:], game) @@ -107,24 +112,25 @@ def package_projects(_indir: str, _outdir: str, all_projects: dict): for section, subsections in all_projects.items(): for subsection, projects in subsections.items(): for title, project in projects.items(): - print(f'package {title}') + print(f'package {title}', file=sys.stderr) projectindir = indir / section / subsection / title projectoutdir = outdir / section / subsection / title - infile = projectindir / project['entry'] + infile = projectindir / project['Datei'] - print(projectindir / 'meta.toml', projectoutdir / 'meta.toml') shutil.copyfile(projectindir / 'meta.toml', projectoutdir / 'meta.toml') + if 'Download' in project: + shutil.copyfile(projectindir / project['Download'], + projectoutdir / project['Download']) + # The project is not a scratch file if not infile.suffix == '.sb3': - print(infile, projectoutdir / project['entry']) - shutil.copyfile(infile, projectoutdir / project['entry']) + shutil.copyfile(infile, projectoutdir / project['Datei']) continue cmd = _cmd.format(infile='..' / infile, outdir='..' / projectoutdir) - print(cmd) subprocess.run(cmd, cwd='turbowarp-packager-cli', check=True, shell=True) - project['entry'] = 'demo_output.html' + project['Datei'] = 'demo_output.html' def main(): @@ -134,6 +140,9 @@ def main(): parser.add_argument('--title', default='Scratch Galerie') parser.add_argument('--no-license', action='store_true') parser.add_argument('--projects-dir', default='projects', help='location of the projects') + parser.add_argument('--no-packaging', + action='store_true', + help='do not package all encountered scratch projects') parser.add_argument('--output-dir', default='build', help='output location of the generated HTML code') @@ -142,11 +151,12 @@ def main(): env = Environment(loader=FileSystemLoader("templates"), autoescape=select_autoescape()) projects = load_projects(args.projects_dir) - print(projects, file=sys.stderr) + # print(projects, file=sys.stderr) prepare_outputdir(args.output_dir, projects) - package_projects(args.projects_dir, args.output_dir, projects) + if not args.no_packaging: + package_projects(args.projects_dir, args.output_dir, projects) template = env.get_template("index.html") with open(pathlib.Path(args.output_dir) / 'index.html', 'w', encoding='utf-8') as outfile: |
