forked from varia/distribusi
small edits
This commit is contained in:
parent
1efb44aaad
commit
442c38e45a
@ -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)
|
||||
|
@ -1,25 +0,0 @@
|
||||
html_head = """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Generated with distribusi https://git.vvvvvvaria.org/varia/distribusi -->
|
||||
<meta name="generator" content="distribusi" />
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<style>
|
||||
.image{max-width: 100%%;}
|
||||
.pdf object{width:640px;height: 640px;}
|
||||
.dir::before{content:"📁 ";font-size:18px;}
|
||||
.filename{display:block;font-family:mono;}
|
||||
.unkown-file::before{content:"📄 ";font-size:18px;}
|
||||
div{max-width: 640px;display:inline-block;vertical-align:top;margin:1em;padding:1em;}
|
||||
video {width:640px;max-height:640px;}
|
||||
%s
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
"""
|
||||
|
||||
html_footer = """
|
||||
</body>
|
||||
</html>
|
||||
"""
|
Loading…
Reference in New Issue
Block a user