mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-27 18:19:32 +00:00
fix: count filename lengths in bytes instead of characters
This commit is contained in:
parent
f5d61b107c
commit
02ee76949b
2 changed files with 11 additions and 7 deletions
|
|
@ -42,8 +42,8 @@ template = '''
|
||||||
'''
|
'''
|
||||||
# Filename template for generated HTML files.
|
# Filename template for generated HTML files.
|
||||||
filename_template = "{{ published_formatted }}\t[{{ origin_title }}]\t{{ title }}.html"
|
filename_template = "{{ published_formatted }}\t[{{ origin_title }}]\t{{ title }}.html"
|
||||||
# Maximum allowed filename length before truncating.
|
# Maximum allowed filename length (in bytes assuming UTF-8 encoding) before truncating. Depending on your filesystem filename's limits it may be possible to increase the value, ask Wikipedia for details.
|
||||||
max_filename_length = 200
|
max_filename_length = 250
|
||||||
|
|
||||||
[time]
|
[time]
|
||||||
# Which timezone to use when writing date and time.
|
# Which timezone to use when writing date and time.
|
||||||
|
|
|
||||||
14
main.py
14
main.py
|
|
@ -114,9 +114,14 @@ def escape_filename(filename):
|
||||||
|
|
||||||
def truncate_filename(config, filename):
|
def truncate_filename(config, filename):
|
||||||
max_filename_length = config.max_filename_length
|
max_filename_length = config.max_filename_length
|
||||||
suffix = Path(filename).suffix
|
filename_utf8 = filename.encode("utf-8")
|
||||||
max_basename_length = max_filename_length - len(suffix)
|
if len(filename_utf8) <= max_filename_length:
|
||||||
return filename[:max_basename_length] + '…' + suffix if len(filename) > max_filename_length else filename
|
return filename
|
||||||
|
else:
|
||||||
|
suffix = Path(filename).suffix
|
||||||
|
max_basename_length = max_filename_length - len(suffix.encode("utf-8"))
|
||||||
|
cutoff = len(filename.encode('utf-8')[:max_basename_length].decode('utf-8', errors="ignore"))
|
||||||
|
return filename[:cutoff] + '…' + suffix
|
||||||
|
|
||||||
def get_html_path(config, item_json):
|
def get_html_path(config, item_json):
|
||||||
folder_directory = config.html_root / escape_filename(item_json["folder"])
|
folder_directory = config.html_root / escape_filename(item_json["folder"])
|
||||||
|
|
@ -124,8 +129,7 @@ def get_html_path(config, item_json):
|
||||||
|
|
||||||
html_name = truncate_filename(config, escape_filename(config.item_filename_template.render(item_json)))
|
html_name = truncate_filename(config, escape_filename(config.item_filename_template.render(item_json)))
|
||||||
|
|
||||||
html_path = folder_directory / html_name
|
return folder_directory / html_name
|
||||||
return html_path
|
|
||||||
|
|
||||||
def format_datetime(config, timestamp):
|
def format_datetime(config, timestamp):
|
||||||
return datetime.fromtimestamp(timestamp, config.timezone).strftime(config.time_format)
|
return datetime.fromtimestamp(timestamp, config.timezone).strftime(config.time_format)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue