diff --git a/README.md b/README.md
index dac96b2..aa8c92a 100755
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ We recommend you to structure your project directory like this:
│ ├── root.html
│ └── titlepage.html
├── meta.yml
+ ├── legal.yml
├── onpoint
│ ├── autocompile.sh
│ ├── main.py
@@ -42,6 +43,7 @@ We recommend you to structure your project directory like this:
* `onpoint` is where this program lives.
* In `layouts`, you can create custom templates for your slides.
* `meta.yml` is there to add language-specific meta information (like title internationalization).
+* `legal.yml` contains links to the privacy policy and imprint that ought to be rendered into the help menu.
* `slides.yml` will contain a list of all chapters to be included. Their content is expected to live in files inside the `slides` folder.
* You can store your usual web resources in the folders `styles` and `images`.
diff --git a/cache.py b/cache.py
index 950bec9..fa92ca0 100755
--- a/cache.py
+++ b/cache.py
@@ -47,12 +47,12 @@ def not_cached_before(root, lang, file):
# Restore the cached chapter.
def get_cached_chapter(root, lang, chapter):
chapter_path = os.path.join(root, '.onpoint', lang, chapter + '.cache')
- return open(chapter_path, 'r').read()
+ return open(chapter_path, 'r', encoding='utf8').read()
# Store a cached version of a chapter.
def store_cached_chapter(root, lang, chapter, content):
chapter_path = os.path.join(root, '.onpoint', lang, chapter + '.cache')
- chapter_file = open(chapter_path, 'w')
+ chapter_file = open(chapter_path, 'w', encoding='utf-8')
chapter_file.write(content)
chapter_file.close()
@@ -66,12 +66,12 @@ def __init_cache_directory(root, lang):
# Save the current time to the timestamp file.
def save_compile_timestamp(root, lang, file_name=timestamp_file_name):
timestamp_file_path = os.path.join(root, '.onpoint', lang, file_name)
- timestamp_file = open(timestamp_file_path, 'w')
+ timestamp_file = open(timestamp_file_path, 'w', encoding='utf-8')
timestamp_file.write(str(int(time.time())))
timestamp_file.close()
# Retrieve the compile timestamp.
def __get_last_compile_time(root, lang):
timestamp_file_path = os.path.join(root, '.onpoint', lang, timestamp_file_name)
- with open(timestamp_file_path) as f:
+ with open(timestamp_file_path, encoding='utf8') as f:
return int(f.readline())
diff --git a/chapters.py b/chapters.py
index f02f27e..4afed56 100755
--- a/chapters.py
+++ b/chapters.py
@@ -21,7 +21,7 @@ def compile_chapters(root_directory, language, force_recompile=False):
chapters = ""
for chapter in structure:
- chapters += '
+ Imprint and privacy policy +
\ No newline at end of file diff --git a/helper.py b/helper.py index e8ad754..f0db7bf 100755 --- a/helper.py +++ b/helper.py @@ -6,7 +6,7 @@ import re # Calls a YAML parser for the given relative path inside the presentation root # directory. Returns a dictionary with the YAML content. def read_yaml(root, path): - with open(os.path.join(root, path), 'r') as stream: + with open(os.path.join(root, path), 'r', encoding='utf8') as stream: try: return yaml.safe_load(stream) except yaml.YAMLError as exc: @@ -47,5 +47,7 @@ def add_lazyload(source, lazyload_images): # per presentation. def add_help_menu(source, root): help_menu_code = open(os.path.join( - root, 'onpoint/help-menu.html'), "r").read() + root, 'onpoint/help-menu.html'), 'r', encoding='utf8').read() + help_menu_code = re.sub('@imprint', read_yaml(root, 'legal.yml')['imprint'], help_menu_code) + help_menu_code = re.sub('@privacy-policy', read_yaml(root, 'legal.yml')['privacy-policy'], help_menu_code) return re.sub('@help', help_menu_code, source) diff --git a/main.py b/main.py index 30fcdb6..bc506ad 100755 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ import helper def compile(root, language='en', force_recompile=False, lazyload_images=False, no_helpmenu=False): - wrapper = open(os.path.join(root, 'layouts/root.html'), 'r').read() + 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) @@ -21,9 +21,10 @@ def compile(root, language='en', force_recompile=False, lazyload_images=False, n wrapper = helper.add_lazyload(wrapper, lazyload_images) if not no_helpmenu: - wrapper = helper.add_help_menu(wrapper, root) - - with open(os.path.join(root, 'slides.' + language + '.html'), 'w+') as output: + 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') diff --git a/requirements.txt b/requirements.txt index 9d690da..c0165bc 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pypandoc==1.4 -lxml==4.5.0 \ No newline at end of file +lxml==4.8.0 +pyyaml==6.0 \ No newline at end of file diff --git a/slides.py b/slides.py index b031cf7..f54cad8 100755 --- a/slides.py +++ b/slides.py @@ -14,17 +14,27 @@ def compile_slide(slide, root_directory): slide_metadata = get_slide_metadata(slide) slide_data = get_slide_data(slide) slide = get_slide_layout(slide_metadata['layout']) + if 'todo' in slide_data.keys(): # TODO: Move the css into a global onpoint.css file slide = '' + slide + for key, value in slide_data.items(): placeholder = '@' + key filler = convert_slide_content(value) - # print('replace', placeholder, 'with', filler) - if '@' + key in slide: + + # very unelegant attempt at inline elements + inline_key = '@' + key + '(inline)' + if inline_key in slide: + slide = slide.replace( + inline_key, + re.sub(r"(.+)
", r"\1", filler) + ) + + elif '@' + key in slide: slide = slide.replace(placeholder, filler) - # very unelegant attempt at inline elements - slide = re.sub(r"(.+?)
\n\(inline\)", r"\1", slide) + + return slide # Parses the metadata passage of a given slide and returns the metadata as a @@ -53,7 +63,7 @@ def get_slide_data(slide): def get_slide_layout(layout_name): global root try: - return open(os.path.join(root, 'layouts/' + layout_name + '.html'), 'r').read() + return open(os.path.join(root, 'layouts/' + layout_name + '.html'), 'r', encoding='utf8').read() except FileNotFoundError: raise Exception('Layout ' + layout_name + ' not found!')