From 0f8b7e718766e7d5bfc4c44769a616406b0c4187 Mon Sep 17 00:00:00 2001 From: RRA Date: Sun, 26 Mar 2017 18:56:41 +0200 Subject: [PATCH] adding support for expanding plain text, html, code and pdf --- distribusi.py | 19 +++++++++++++++---- page_template.py | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/distribusi.py b/distribusi.py index eb00de7..f409d31 100755 --- a/distribusi.py +++ b/distribusi.py @@ -23,9 +23,12 @@ else: mime_type = magic.Magic(mime=True) -file_types = {'image':'', 'pdf':'{}', +file_types = {'image':'', 'pdf':'', 'text':'{}', 'video':'', 'audio':'','html':'{}'} +code_types = ['x-c', 'html'] + + def dict_by_value(dictionary, value): return(list(dictionary.keys())[list(dictionary.values()).index(value)]) # returns the key for the given value def div(mime, tag, *values): @@ -33,6 +36,9 @@ def div(mime, tag, *values): class_name = values[0].split('.')[0].replace(' ', '_') if 'image' in mime: html ='
'.format(class_name)+tag+'
{}
'.format(values[0]) + + elif 'pdf' in format: + html ='
'.format(class_name)+tag+'
{}
'.format(values[0]) else: html = '
'.format(class_name)+tag+'
'.format(values[0]) return html @@ -52,9 +58,14 @@ for root, dirs, files in os.walk(directory): if args.verbose: print(mime, format) - if mime in file_types: - if name.endswith('.html'): - a = open(full_path).read() + if mime in file_types: #expansion for different kind of textfiles + if mime == 'text': + if name.endswith('.html') or name.endswith('.txt'): #what types of text files to expand + a = open(full_path).read() + elif format in code_types: #if the plain text is code, which types do we wrap in pre-tags? + a = "
"+open(full_path).read()+"
" + else: + a = file_types[mime] else: a = file_types[mime] diff --git a/page_template.py b/page_template.py index da22458..1a3f256 100644 --- a/page_template.py +++ b/page_template.py @@ -8,7 +8,8 @@ html_head = """