forked from varia/distribusi
small edits
This commit is contained in:
parent
1efb44aaad
commit
442c38e45a
@ -2,6 +2,7 @@ import os
|
|||||||
|
|
||||||
import magic
|
import magic
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from distribusi.page_template import html_footer, html_head
|
from distribusi.page_template import html_footer, html_head
|
||||||
from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES
|
from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES
|
||||||
|
|
||||||
@ -94,22 +95,12 @@ def check_distribusi_index(args, index):
|
|||||||
return True
|
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:
|
with open(index, "w") as index_file:
|
||||||
if not args.no_template:
|
rendered_html = template.render(content = html)
|
||||||
if args.style:
|
index_file.write(rendered_html)
|
||||||
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):
|
def handle_text_files(name, full_path, subtype):
|
||||||
@ -211,7 +202,9 @@ def distribusify(args, directory): # noqa
|
|||||||
if type_ in FILE_TYPES:
|
if type_ in FILE_TYPES:
|
||||||
match type_:
|
match type_:
|
||||||
case "text":
|
case "text":
|
||||||
subtype, tag = handle_text_files(name, full_path, subtype)
|
subtype, tag = handle_text_files(
|
||||||
|
name, full_path, subtype
|
||||||
|
)
|
||||||
case "image":
|
case "image":
|
||||||
tag = handle_image_files(name, full_path, args)
|
tag = handle_image_files(name, full_path, args)
|
||||||
if tag is None:
|
if tag is None:
|
||||||
@ -252,6 +245,6 @@ def distribusify(args, directory): # noqa
|
|||||||
index = os.path.join(root, "index.html")
|
index = os.path.join(root, "index.html")
|
||||||
if os.path.exists(index):
|
if os.path.exists(index):
|
||||||
if check_distribusi_index(args, 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):
|
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>
|
|
||||||
"""
|
|
2
setup.py
2
setup.py
@ -11,7 +11,7 @@ with open("README.md", "r") as handle:
|
|||||||
setup(
|
setup(
|
||||||
name="distribusi",
|
name="distribusi",
|
||||||
version="0.0.11",
|
version="0.0.11",
|
||||||
url="https://git.vvvvvvaria.org/varia/distribusi",
|
url="https://git.vvvvvvaria.org/crunk/distribusi",
|
||||||
license="GPLv3",
|
license="GPLv3",
|
||||||
author="Varia",
|
author="Varia",
|
||||||
description=(
|
description=(
|
||||||
|
Loading…
Reference in New Issue
Block a user