Browse Source

files are listed alphabetically, fixes to css and html

master
rra 5 years ago
parent
commit
6a9fbe9856
  1. 16
      distribusi/distribusi.py
  2. 4
      distribusi/mappings.py
  3. 8
      distribusi/page_template.py

16
distribusi/distribusi.py

@ -116,17 +116,23 @@ def distribusify(args, directory): # noqa
if args.verbose: if args.verbose:
print('Generating directory listing for', root) print('Generating directory listing for', root)
for name in files: for name in sorted(files):
if 'index.html' not in name: if 'index.html' not in name:
full_path = os.path.join(root, name) full_path = os.path.join(root, name)
mime = MIME_TYPE.from_file(full_path) mime = MIME_TYPE.from_file(full_path)
# example: MIME plain/text becomes 'type' plain 'subtype' text # example: MIME plain/text becomes 'type' plain 'subtype' text
type_, subtype = mime.split('/') type_, subtype = mime.split('/')
caption = name
if args.verbose: if args.verbose:
print('Found', name, 'as', mime) print('Found', name, 'as', mime)
if type_ in FILE_TYPES: if type_ in FILE_TYPES:
a = FILE_TYPES[type_].format(name, caption)
# expansion for different kind of text files # expansion for different kind of text files
if type_ == 'text': if type_ == 'text':
if name.endswith('.html') or subtype == 'html': if name.endswith('.html') or subtype == 'html':
@ -143,14 +149,12 @@ def distribusify(args, directory): # noqa
# a = FILE_TYPES[type_] # a = FILE_TYPES[type_]
if type_ == 'image': if type_ == 'image':
caption = name
if args.thumbnail: if args.thumbnail:
a = thumbnail(full_path, name, args) a = thumbnail(full_path, name, args)
if args.no_filenames: if args.no_filenames:
caption = "" caption = ""
if args.captions: if args.captions:
caption = caption(full_path) caption = caption(full_path)
a = FILE_TYPES[type_].format(name, caption) a = FILE_TYPES[type_].format(name, caption)
if subtype in SUB_TYPES: if subtype in SUB_TYPES:
@ -162,8 +166,10 @@ def distribusify(args, directory): # noqa
if args.verbose: if args.verbose:
message = 'not in list of file types, adding as plain href: \n' message = 'not in list of file types, adding as plain href: \n'
print(type_, subtype, message, name) print(type_, subtype, message, name)
type_ = 'unkown-file' subtype = subtype + ' unkown-file'
a = a.replace('{}', name) a = a.replace('{}', name)
html.append(div(args, type_, subtype, a, name)) html.append(div(args, type_, subtype, a, name))
if root != directory: if root != directory:
@ -180,8 +186,6 @@ def distribusify(args, directory): # noqa
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, html_head, html_footer)
if args.remove_index: if args.remove_index:
index = os.path.join(root, 'index.html') index = os.path.join(root, 'index.html')
if 'index.html' in files: if 'index.html' in files:

4
distribusi/mappings.py

@ -3,8 +3,8 @@ CODE_TYPES = ['x-c', 'x-shellscript', 'x-python']
FILE_TYPES = { FILE_TYPES = {
'image': '<figure><img class="image" src="{}"><figcaption>{}</figcaption></figure>', 'image': '<figure><img class="image" src="{}"><figcaption>{}</figcaption></figure>',
'text': '<a href="{}" class="text">{}</a>', 'text': '<a href="{}" class="text">{}</a>',
'video': ('<video class="video" controls>' '<source src="{}"></source></video>'), 'video': ('<video controls>' '<source src="{}"></video>'),
'audio': ('<audio controls class="audio">' '<source src="{}"></source></audio>'), 'audio': ('<audio controls class="audio">' '<source src="{}"></audio>'),
} }
SUB_TYPES = { SUB_TYPES = {

8
distribusi/page_template.py

@ -7,12 +7,12 @@ html_head = """
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<style> <style>
.image{max-width: 100%%;} .image{max-width: 100%%;}
.pdf object{width:100%%;} .pdf object{width:640px;height: 640px;}
.dir::before{content:"📁 ";font-size:18px;} .dir::before{content:"📁 ";font-size:18px;}
.filename{display:block;} .filename{display:block;font-family:mono;}
.unkown-file::before{content:"📄 ";font-size:18px;} .unkown-file::before{content:"📄 ";font-size:18px;}
div{width: 640px;float:left;padding:1em;} div{max-width: 640px;display:inline-block;vertical-align:top;margin:1em;padding:1em;}
video {width:640px;} video {width:640px;max-height:640px;}
%s %s
</style> </style>
</head> </head>

Loading…
Cancel
Save