From 4769262b2d72bfef44b66e616c06207ffc2058be Mon Sep 17 00:00:00 2001 From: Konrad Paluszek Date: Sat, 12 Oct 2024 22:52:11 +0200 Subject: [PATCH] Generate quiz-output.html if there's exactly one version --- generate.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/generate.py b/generate.py index 0d42205..bf8b8da 100644 --- a/generate.py +++ b/generate.py @@ -54,10 +54,20 @@ def main(): content.append(escape(get_file(filename, content_branch))) output = '[' + ','.join(content) + ']' - index = get_file('index.html', from_branch) - with open('output.html', 'w') as output_file: - index = index.replace('resources', 'resources_main').replace('hardcoded=undefined', 'hardcoded=' + output); - print(index, file=output_file) + to_process = [['index.html', 'output.html']] + if len(content) == 1: + to_process.append(['quiz.html', 'quiz-output.html']) + else: + try: + os.remove('quiz-output.html') + except FileNotFoundError: + pass + + for input_name, output_name in to_process: + content = get_file(input_name, from_branch) + with open(output_name, 'w') as output_file: + content = content.replace('resources', 'resources_main').replace('hardcoded=undefined', 'hardcoded=' + output); + print(content, file=output_file) subprocess.run(['rm', '-rf', 'resources_main']) os.mkdir('resources_main') for dirname in get_file('resources/all_directories_list', from_branch).split('\n'):