38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import os
|
|
|
|
import helper
|
|
import slides as slides_helper
|
|
|
|
root = ""
|
|
lang = ""
|
|
|
|
# Compiles a presentation's chapters (the content without the wrapper)
|
|
# according to slides.yml and returns them as one string of <section>s.
|
|
def compile_chapters(root_directory, language):
|
|
global root
|
|
root = root_directory
|
|
|
|
global lang
|
|
lang = language
|
|
|
|
structure = helper.read_yaml(root, 'slides.yml')
|
|
chapters = ""
|
|
for chapter in structure:
|
|
chapters += '<section>\n' + compile_chapter(chapter) + '\n</section>'
|
|
return chapters # string
|
|
|
|
# Compiles a presentation's chapter (given its name) by splitting it into
|
|
# slides, compiling those, and returning them as a string of <article>s.
|
|
def compile_chapter(chapter):
|
|
global root
|
|
if type(chapter) != str:
|
|
raise Exception('Chapters with attributes are not supported yet.\n' +
|
|
str(chapter))
|
|
chapter_file = open(os.path.join(root, 'slides/' + chapter + '.' + lang + '.md'), 'r')
|
|
delimiter = '\n@slide'
|
|
chapter_input = ('\n' + chapter_file.read()).split(delimiter)
|
|
slides = [delimiter + slide for slide in chapter_input][1:]
|
|
chapter = ''
|
|
for slide in slides:
|
|
chapter += '<article>\n' + slides_helper.compile_slide(slide, root) + '\n</article>\n'
|
|
return chapter |