diff --git a/distribusi/distribusi.py b/distribusi/distribusi.py index fd052cf..fba0553 100644 --- a/distribusi/distribusi.py +++ b/distribusi/distribusi.py @@ -2,8 +2,13 @@ import os import magic from PIL import Image -from jinja2 import Environment, FileSystemLoader from distribusi.page_template import html_footer, html_head +from distribusi.image_templates import ( + no_description, + with_description, + with_alttext, + full_figure, +) from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES MIME_TYPE = magic.Magic(mime=True) @@ -96,11 +101,21 @@ def check_distribusi_index(args, index): def write_index(args, index, html): - env = Environment(loader = FileSystemLoader('templates')) - template = env.get_template('main.jinja') with open(index, "w") as index_file: - rendered_html = template.render(content = html) - index_file.write(rendered_html) + if not args.no_template: + if args.style: + file_style = open(args.style, "r") + style = file_style.read() + styled_html_head = html_head % style + else: + styled_html_head = html_head % "" + index_file.write(styled_html_head) + + for line in html: + index_file.write(line + "\n") + + if not args.no_template: + index_file.write(html_footer) def handle_text_files(name, full_path, subtype): @@ -132,11 +147,26 @@ def handle_image_files(name, full_path, args): image_description = add_description(full_path) if image_alttext is None: if image_description is None: - return f'' - return f'' + return image_no_description.format( + name=name, thumbnail_filename=thumbnail_filename + ) + return image_with_description.format( + name=name, + thumbnail_filename=thumbnail_filename, + image_description=image_description, + ) if image_description is None: - return f'' - return f'' + return image_with_alttext.format( + name=name, + thumbnail_filename=thumbnail_filename, + image_alttext=image_alttext, + ) + return image_full_figure.format( + name=name, + thumbnail_filename=thumbnail_filename, + image_alttext=image_alttext, + image_description=image_description, + ) return FILE_TYPES["image"].format(name, image_alttext) diff --git a/distribusi/templates/__init__.py b/distribusi/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/distribusi/templates/image_templates.py b/distribusi/templates/image_templates.py new file mode 100644 index 0000000..565f587 --- /dev/null +++ b/distribusi/templates/image_templates.py @@ -0,0 +1,4 @@ +image_no_description = '' +image_with_description = '' +image_with_alttext = '' +image_full_figure = '' diff --git a/distribusi/templates/page_template.py b/distribusi/templates/page_template.py new file mode 100644 index 0000000..1d70ccc --- /dev/null +++ b/distribusi/templates/page_template.py @@ -0,0 +1,25 @@ +html_head = """ + + +
+ + + + + + +""" + +html_footer = """ + + +""" diff --git a/setup.py b/setup.py index 1663f6a..e816c88 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ with open("README.md", "r") as handle: setup( name="distribusi", - version="0.0.11", + version="0.0.12", url="https://git.vvvvvvaria.org/crunk/distribusi", license="GPLv3", author="Varia",