Merge branch 'master' of git.stuve-bamberg.de:ckremitzl/onpoint
This commit is contained in:
commit
814d661810
@ -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`.
|
||||
|
||||
|
||||
8
cache.py
8
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())
|
||||
|
||||
@ -21,7 +21,7 @@ def compile_chapters(root_directory, language, force_recompile=False):
|
||||
|
||||
chapters = ""
|
||||
for chapter in structure:
|
||||
chapters += '<section>\n' + compile_chapter(chapter, no_cache) + '\n</section>'
|
||||
chapters += '<section>' + os.linesep + compile_chapter(chapter, no_cache) + os.linesep + '</section>'
|
||||
|
||||
cache.save_compile_timestamp(root, lang)
|
||||
return chapters # string
|
||||
@ -47,7 +47,7 @@ def compile_chapter(chapter, no_cache):
|
||||
return cache.get_cached_chapter(root, lang, chapter)
|
||||
|
||||
print("Recompiling chapter " + chapter + " (" + lang + ").")
|
||||
chapter_file = open(chapter_path, 'r')
|
||||
chapter_file = open(chapter_path, 'r', encoding='utf-8')
|
||||
delimiter = '\n@slide'
|
||||
chapter_input = ('\n' + chapter_file.read()).split(delimiter)
|
||||
slides = [delimiter + slide for slide in chapter_input][1:]
|
||||
|
||||
@ -14,6 +14,7 @@ FRAGMENT_CLASS = "fragment"
|
||||
|
||||
def defragmentize(html):
|
||||
dom = etree.fromstring(html)
|
||||
|
||||
query = "|".join([
|
||||
# FRAGMENT_TAG between two spaces
|
||||
"//*[contains(text(), ' %s ')]" % FRAGMENT_TAG,
|
||||
@ -33,7 +34,7 @@ def defragmentize(html):
|
||||
|
||||
fragment.set('class', class_list)
|
||||
fragment.text = re.sub(r"\s*%s\s*" %
|
||||
re.escape(FRAGMENT_TAG), '', fragment.text)
|
||||
re.escape(FRAGMENT_TAG), '', fragment.text)
|
||||
|
||||
return etree.tostring(dom, method='html', encoding='utf-8',
|
||||
pretty_print=True).decode('utf-8')
|
||||
|
||||
@ -9,4 +9,7 @@
|
||||
<li>Close slide overview: <kbd>Esc</kbd></li>
|
||||
<li>Open the help menu: <kbd>H</kbd></li>
|
||||
</ul>
|
||||
<p>
|
||||
<a href="@imprint">Imprint</a> and <a href="@privacy-policy">privacy policy</a>
|
||||
</p>
|
||||
</div>
|
||||
@ -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)
|
||||
|
||||
9
main.py
9
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')
|
||||
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
pypandoc==1.4
|
||||
lxml==4.5.0
|
||||
lxml==4.8.0
|
||||
pyyaml==6.0
|
||||
20
slides.py
20
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 = '<aside class="todo" style="position:absolute; z-index:100; display:block; background:rgba(255,0,0,.8); top:0; right:0; max-width:20%; margin:.5em; padding:.5em; border-radius:1em; font-family:sans-serif; font-size: .8em;">@todo</aside>' + 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"<p>(.+)</p>", r"\1", filler)
|
||||
)
|
||||
|
||||
elif '@' + key in slide:
|
||||
slide = slide.replace(placeholder, filler)
|
||||
# very unelegant attempt at inline elements
|
||||
slide = re.sub(r"<p>(.+?)</p>\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!')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user