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

feat: make remove empty categories configurable

This commit is contained in:
Étienne Fildadut 2025-10-11 15:11:11 +02:00
parent e271b3776a
commit a63f71f711
3 changed files with 12 additions and 5 deletions

View file

@ -108,6 +108,9 @@ filename_template = "[{{ feed_title }}]\t{{ title }} ({{ published_formatted }})
# - order: category display order, starting from 1 (0 if unknown) (int) # - order: category display order, starting from 1 (0 if unknown) (int)
# Can be set through the environment variable HTML_CATEGORY_TEMPLATE. # Can be set through the environment variable HTML_CATEGORY_TEMPLATE.
category_template = "{% if order %}{{ '%02d' % order }} {% endif %}{{ title }}" category_template = "{% if order %}{{ '%02d' % order }} {% endif %}{{ title }}"
# Set to true to automatically remove category directories when they do not contain any article.
# Can be set through the environment variable HTML_HIDE_EMPTY_CATEGORIES.
hide_empty_categories = true
# 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. # 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.
# Can be set through the environment variable HTML_MAX_FILENAME_LENGTH. # Can be set through the environment variable HTML_MAX_FILENAME_LENGTH.
max_filename_length = 250 max_filename_length = 250

View file

@ -58,6 +58,7 @@ class Config:
self.article_template: Template = Template(str(get_config("html", "article_template")), autoescape=True) self.article_template: Template = Template(str(get_config("html", "article_template")), autoescape=True)
self.article_filename_template: Template = Template(str(get_config("html", "filename_template")), autoescape=False) self.article_filename_template: Template = Template(str(get_config("html", "filename_template")), autoescape=False)
self.article_category_template: Template = Template(str(get_config("html", "category_template")), autoescape=False) self.article_category_template: Template = Template(str(get_config("html", "category_template")), autoescape=False)
self.hide_empty_categories: bool = bool(get_config("html", "hide_empty_categories"))
self.max_filename_length: int = int(get_config("html", "max_filename_length")) self.max_filename_length: int = int(get_config("html", "max_filename_length"))
self.filename_translation = str.maketrans(get_config("html", "filename_replacement")) self.filename_translation = str.maketrans(get_config("html", "filename_replacement"))

View file

@ -28,7 +28,7 @@ class FeatherApp:
raise ValueError(f"{api} server type is invalid; must be ttrss or googlereader") raise ValueError(f"{api} server type is invalid; must be ttrss or googlereader")
return self._client_session return self._client_session
def remove_empty_html_directories(self): def remove_empty_categories(self):
"""Remove empty directories in the HTML directory""" """Remove empty directories in the HTML directory"""
config = self.config config = self.config
html_root = config.html_root html_root = config.html_root
@ -118,17 +118,20 @@ class FeatherApp:
"""Do a full feather update""" """Do a full feather update"""
self.mark_deleted_as_read() self.mark_deleted_as_read()
self.synchronize_with_server() self.synchronize_with_server()
self.remove_empty_html_directories() if self.config.hide_empty_categories:
self.remove_empty_categories()
def synchronize_local_changes(self): def synchronize_local_changes(self):
"""Upload local changes (read articles) to the server""" """Upload local changes (read articles) to the server"""
self.mark_deleted_as_read() self.mark_deleted_as_read()
self.remove_empty_html_directories() if self.config.hide_empty_categories:
self.remove_empty_categories()
def synchronize_remote_changes(self): def synchronize_remote_changes(self):
"""Download remote changes (new articles, articles read from another device) from the server""" """Download remote changes (new articles, articles read from another device) from the server"""
self.synchronize_with_server() self.synchronize_with_server()
self.remove_empty_html_directories() if self.config.hide_empty_categories:
self.remove_empty_categories()
async def daemon_sync_up_loop(self): async def daemon_sync_up_loop(self):
while True: while True:
@ -161,5 +164,5 @@ class FeatherApp:
config = self.config config = self.config
for json_path in config.json_root.glob("*.json"): for json_path in config.json_root.glob("*.json"):
FileArticle(config, json_path).delete() FileArticle(config, json_path).delete()
self.remove_empty_html_directories() self.remove_empty_categories()