diff --git a/distribusi/distribusi/distribusi.py b/distribusi/distribusi/distribusi.py index 1634180..f336ce8 100644 --- a/distribusi/distribusi/distribusi.py +++ b/distribusi/distribusi/distribusi.py @@ -3,6 +3,7 @@ import base64 import os import subprocess +import re from io import BytesIO @@ -21,6 +22,8 @@ MIME_TYPE = magic.Magic(mime=True) ignore = Ignore() +PATTERN_TAG = re.compile(r"(?P.+?)(?P\@.+)*\.(?P.+)") +PATTERN_TAG_FOLDER = re.compile(r"(?P.+?)(?P\@.+)\/(?P.+)") def caption(image): try: @@ -75,18 +78,40 @@ def thumbnail(image, name, args): cap = caption(image) else: cap = name + + m = PATTERN_TAG_FOLDER.search(cap) + if m: + folder_name = m.group('name') + file_name = m.group('file') + cap = folder_name + "/" + file_name + return ( "
{}
" ).format(name, data_url, cap) except Exception as e: print('Thumbnailer:', e) - return "
{}
".format(name, name, name) + cap = name + m = PATTERN_TAG_FOLDER.search(cap) + if m: + folder_name = m.group('name') + file_name = m.group('file') + cap = folder_name + "/" + file_name + return "
{}
".format(name, name, cap) def div(args, type_, subtype, tag, name, fid): ''' fid: fragment_id ''' + + + + m = PATTERN_TAG.search(name) + if m: + file_name = m.group('name') + file_ext = m.group('ext') + name = file_name + "." + file_ext + if args.no_filenames: filename = '' else: @@ -94,13 +119,13 @@ def div(args, type_, subtype, tag, name, fid): if len(str(fid)) >= 36 or int(fid) < 0: # detect if fid is uuid if 'image' in type_: - html = '
{}
' + html = '️
{}
' elif 'pdf' in subtype: html = '
{}' + filename + '
' elif 'dir' in type_ or 'html' in subtype or 'unkown-file' in subtype: html = '
{}
' else: - html = '
{}' + filename + '
' + html = '️
{}' + filename + '
' html = html.format(subtype, tag) else: if 'image' in type_: @@ -108,9 +133,9 @@ def div(args, type_, subtype, tag, name, fid): elif 'pdf' in subtype: html = '
{}' + filename + '#{}
' elif 'dir' in type_ or 'html' in subtype or 'unkown-file' in subtype: - html = '
{}#{}
' + html = '️
{}#{}
' else: - html = '
{}' + filename + '#{}
' + html = '️
{}' + filename + '#{}
' html = html.format(subtype, fid, tag, fid) return html diff --git a/test_data/.ignore b/test_data/.ignore index 97a206e..d7ddbe3 100644 --- a/test_data/.ignore +++ b/test_data/.ignore @@ -12,4 +12,7 @@ style.css 404.html main.js .+.alt -events \ No newline at end of file +events +human +tech +environment \ No newline at end of file