onpoint/main.py
2025-11-23 12:20:50 +01:00

55 lines
2.4 KiB
Python
Executable File

#!/usr/bin/python3
import argparse
import os
import sys
import chapters
import fragments
import helper
# Compiles a presentation in the given language from the given directory and
# stores it in a corresponding slides.lang.html file inside the same directory.
def compile(root, language='en', force_recompile=False, lazyload_images=False, no_help_menu=False):
wrapper = open(os.path.join(root, 'layouts/root.html'), 'r', encoding='utf8').read()
compiled_chapters = chapters.compile_chapters(root, language, force_recompile)
wrapper = wrapper.replace('@slides', compiled_chapters)
wrapper = helper.insert_metadata(wrapper, root, language)
wrapper = fragments.defragmentize(wrapper)
wrapper = helper.add_lazyload(wrapper, lazyload_images)
if not no_help_menu:
with open(os.path.join(root, 'slides.' + language + '.html'), 'w+') as output:
wrapper = helper.add_help_menu(wrapper, root)
with open(os.path.join(root, 'slides.' + language + '.html'), 'w+', encoding='utf8') as output:
output.write(wrapper)
print('done')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("root_directory", help="your project's root directory")
parser.add_argument("-l", "--language", default="all",
help="the presentation language (default: all)")
parser.add_argument("-f", "--force-recompile", action='store_true',
help="recompile the entire presentation without caches")
parser.add_argument("-i", "--lazyload-images", action='store_true',
help="replace all images' src attributes by data-src for image lazyloading")
parser.add_argument("-n", "--no-help-menu", action="store_true", help="do not compile the help menu")
args = parser.parse_args()
force_recompile = False or args.force_recompile
lazyload_images = False or args.lazyload_images
no_help_menu = False or args.no_help_menu
if args.language == "all":
for language in helper.get_available_languages(args.root_directory):
compile(args.root_directory, language=language,
force_recompile=force_recompile, lazyload_images=lazyload_images, no_help_menu=no_help_menu)
else:
compile(args.root_directory, language=args.language,
force_recompile=force_recompile, lazyload_images=lazyload_images, no_help_menu=no_help_menu)