1
0
Fork 0
mirror of https://codeberg.org/Reuh/feather.git synced 2025-10-27 18:19:32 +00:00

feat: make filename escaping configurable

This commit is contained in:
Étienne Fildadut 2025-10-09 16:33:08 +02:00
parent 02ee76949b
commit 06dc961d62
3 changed files with 8 additions and 5 deletions

View file

@ -21,7 +21,7 @@
- [ ] Nested categories
- [ ] Share the fun somewhere
- [x] Edge cases: mark as read during sync (if marked as read on server or not)
- [ ] Proper filename escaping
- [x] Proper filename escaping
- [ ] Command to force regenerate all HTML files (incl. recompute datetimes & paths)
- [ ] Handle item updates

View file

@ -44,6 +44,8 @@ template = '''
filename_template = "{{ published_formatted }}\t[{{ origin_title }}]\t{{ title }}.html"
# 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 = 250
# Table mapping characters to what they will be replaced with in filenames. Useful to remove/replace characters that are not allowed in filename by your filesystem. The default should be fine for most Unix filesystems.
filename_replacement = { "/" = "", "\u0000" = "" }
[time]
# Which timezone to use when writing date and time.

View file

@ -46,6 +46,7 @@ class Config:
self.item_template: Template = Template(get_config("html", "template"), autoescape=True)
self.item_filename_template: Template = Template(get_config("html", "filename_template"), autoescape=False)
self.max_filename_length: int = int(get_config("html", "max_filename_length"))
self.filename_translation = str.maketrans(get_config("html", "filename_replacement"))
# Computed config fields
self.update_lock = self.json_root / "update.lock"
@ -109,8 +110,8 @@ def mark_deleted_as_read(config, client_session):
print(f"Marked {marked_as_read} items as read")
def escape_filename(filename):
return filename.replace("/", "-")
def escape_filename(config, filename):
return filename.translate(config.filename_translation)
def truncate_filename(config, filename):
max_filename_length = config.max_filename_length
@ -124,10 +125,10 @@ def truncate_filename(config, filename):
return filename[:cutoff] + '' + suffix
def get_html_path(config, item_json):
folder_directory = config.html_root / escape_filename(item_json["folder"])
folder_directory = config.html_root / escape_filename(config, item_json["folder"])
folder_directory.mkdir(exist_ok=True)
html_name = truncate_filename(config, escape_filename(config.item_filename_template.render(item_json)))
html_name = truncate_filename(config, escape_filename(config, config.item_filename_template.render(item_json)))
return folder_directory / html_name