49 lines
2.0 KiB
Python
Executable File
49 lines
2.0 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):
|
|
wrapper = open(os.path.join(root, 'layouts/root.html'), 'r').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)
|
|
wrapper = helper.add_help_menu(wrapper, root)
|
|
with open(os.path.join(root, 'slides.' + language + '.html'), 'w+') as output:
|
|
output.write(wrapper)
|
|
print('done')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("rootdirectory", 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")
|
|
|
|
args = parser.parse_args()
|
|
force_recompile = False or args.force_recompile
|
|
lazyload_images = False or args.lazyload_images
|
|
|
|
if args.language == "all":
|
|
for language in helper.get_available_languages(args.rootdirectory):
|
|
compile(args.rootdirectory, language=language,
|
|
force_recompile=force_recompile, lazyload_images=lazyload_images)
|
|
else:
|
|
compile(args.rootdirectory, language=args.language,
|
|
force_recompile=force_recompile, lazyload_images=lazyload_images)
|