hide hashtag on filename

This commit is contained in:
Sewon Ahn 2021-09-12 16:07:29 +09:00
parent 902a53ba8b
commit 6eefd14cc8
2 changed files with 34 additions and 6 deletions

View file

@ -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<name>.+?)(?P<hashes>\@.+)*\.(?P<ext>.+)")
PATTERN_TAG_FOLDER = re.compile(r"(?P<name>.+?)(?P<hashes>\@.+)\/(?P<file>.+)")
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 (
"<figure><a href='{}'><img class='thumbnail' src='data:image/jpg;base64,{}'></a><figcaption>{}</figcaption></figure>"
).format(name, data_url, cap)
except Exception as e:
print('Thumbnailer:', e)
return "<figure><a href='{}'><img src='{}'></a><figcaption>{}</figcaption></figure>".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 "<figure><a href='{}'><img src='{}'></a><figcaption>{}</figcaption></figure>".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 = '<div class="{}">{}</div>'
html = '<div class="{}">{}</div>'
elif 'pdf' in subtype:
html = '<div class="{}">{}' + filename + '</div>'
elif 'dir' in type_ or 'html' in subtype or 'unkown-file' in subtype:
html = '<div class="{}">{}</div>'
else:
html = '<div class="{}">{}' + filename + '</div>'
html = '<div class="{}">{}' + filename + '</div>'
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 = '<div class="{}"><a class="anchor" id="{}"></a>{}' + filename + '<span class="fid">#{}</span></div>'
elif 'dir' in type_ or 'html' in subtype or 'unkown-file' in subtype:
html = '<div class="{}"><a class="anchor" id="{}"></a>{}<span class="fid">#{}</span></div>'
html = '<div class="{}"><a class="anchor" id="{}"></a>{}<span class="fid">#{}</span></div>'
else:
html = '<div class="{}"><a class="anchor" id="{}"></a>{}' + filename + '<span class="fid">#{}</span></div>'
html = '<div class="{}"><a class="anchor" id="{}"></a>{}' + filename + '<span class="fid">#{}</span></div>'
html = html.format(subtype, fid, tag, fid)
return html

View file

@ -12,4 +12,7 @@ style.css
404.html
main.js
.+.alt
events
events
human
tech
environment