diff --git a/distribusi/distribusi.py b/distribusi/distribusi.py index 07b4200..fd052cf 100644 --- a/distribusi/distribusi.py +++ b/distribusi/distribusi.py @@ -2,6 +2,7 @@ import os import magic from PIL import Image +from jinja2 import Environment, FileSystemLoader from distribusi.page_template import html_footer, html_head from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES @@ -94,22 +95,12 @@ def check_distribusi_index(args, index): return True -def write_index(args, index, html, html_head, html_footer): +def write_index(args, index, html): + env = Environment(loader = FileSystemLoader('templates')) + template = env.get_template('main.jinja') with open(index, "w") as index_file: - 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) + rendered_html = template.render(content = html) + index_file.write(rendered_html) def handle_text_files(name, full_path, subtype): @@ -211,7 +202,9 @@ def distribusify(args, directory): # noqa if type_ in FILE_TYPES: match type_: case "text": - subtype, tag = handle_text_files(name, full_path, subtype) + subtype, tag = handle_text_files( + name, full_path, subtype + ) case "image": tag = handle_image_files(name, full_path, args) if tag is None: @@ -252,6 +245,6 @@ def distribusify(args, directory): # noqa index = os.path.join(root, "index.html") if os.path.exists(index): if check_distribusi_index(args, index): - write_index(args, index, html, html_head, html_footer) + write_index(args, index, html) elif not os.path.exists(index): - write_index(args, index, html, html_head, html_footer) + write_index(args, index, html) diff --git a/distribusi/page_template.py b/distribusi/page_template.py deleted file mode 100644 index 24a1e93..0000000 --- a/distribusi/page_template.py +++ /dev/null @@ -1,25 +0,0 @@ -html_head = """ - - -
- - - - - - -""" - -html_footer = """ - - -""" diff --git a/setup.py b/setup.py index 8fdf7de..1663f6a 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ with open("README.md", "r") as handle: setup( name="distribusi", version="0.0.11", - url="https://git.vvvvvvaria.org/varia/distribusi", + url="https://git.vvvvvvaria.org/crunk/distribusi", license="GPLv3", author="Varia", description=(