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 = """