forked from varia/distribusi
reboot my work
This commit is contained in:
parent
442c38e45a
commit
b6a2c7687d
@ -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'<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{name}"></a>'
|
||||
return f'<figure><a href="{name}"><img class="thumbnail" src="{thumbnail_filename}"></a><figcaption>{image_description}</figcaption></figure>'
|
||||
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'<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a>'
|
||||
return f'<figure><a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a><figcaption>{image_description}</figcaption></figure>'
|
||||
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)
|
||||
|
||||
|
||||
|
0
distribusi/templates/__init__.py
Normal file
0
distribusi/templates/__init__.py
Normal file
4
distribusi/templates/image_templates.py
Normal file
4
distribusi/templates/image_templates.py
Normal file
@ -0,0 +1,4 @@
|
||||
image_no_description = '<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{name}"></a>'
|
||||
image_with_description = '<figure><a href="{name}"><img class="thumbnail" src="{thumbnail_filename}"></a><figcaption>{image_description}</figcaption></figure>'
|
||||
image_with_alttext = '<a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a>'
|
||||
image_full_figure = '<figure><a href="{name}"><img class="thumbnail" src="{thumbnail_filename}" alt="{image_alttext}"></a><figcaption>{image_description}</figcaption></figure>'
|
25
distribusi/templates/page_template.py
Normal file
25
distribusi/templates/page_template.py
Normal file
@ -0,0 +1,25 @@
|
||||
html_head = """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Generated with distribusi https://git.vvvvvvaria.org/crunk/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