diff --git a/src/feather/config.default.toml b/src/feather/config.default.toml index 11294a2..0d92952 100644 --- a/src/feather/config.default.toml +++ b/src/feather/config.default.toml @@ -108,6 +108,9 @@ filename_template = "[{{ feed_title }}]\t{{ title }} ({{ published_formatted }}) # - order: category display order, starting from 1 (0 if unknown) (int) # Can be set through the environment variable HTML_CATEGORY_TEMPLATE. 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. # Can be set through the environment variable HTML_MAX_FILENAME_LENGTH. max_filename_length = 250 diff --git a/src/feather/config.py b/src/feather/config.py index fd9d255..c943f3f 100644 --- a/src/feather/config.py +++ b/src/feather/config.py @@ -58,6 +58,7 @@ class Config: 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_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.filename_translation = str.maketrans(get_config("html", "filename_replacement")) diff --git a/src/feather/feather.py b/src/feather/feather.py index 928e45b..78d637a 100755 --- a/src/feather/feather.py +++ b/src/feather/feather.py @@ -28,7 +28,7 @@ class FeatherApp: raise ValueError(f"{api} server type is invalid; must be ttrss or googlereader") return self._client_session - def remove_empty_html_directories(self): + def remove_empty_categories(self): """Remove empty directories in the HTML directory""" config = self.config html_root = config.html_root @@ -118,17 +118,20 @@ class FeatherApp: """Do a full feather update""" self.mark_deleted_as_read() self.synchronize_with_server() - self.remove_empty_html_directories() + if self.config.hide_empty_categories: + self.remove_empty_categories() def synchronize_local_changes(self): """Upload local changes (read articles) to the server""" 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): """Download remote changes (new articles, articles read from another device) from the 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): while True: @@ -161,5 +164,5 @@ class FeatherApp: config = self.config for json_path in config.json_root.glob("*.json"): FileArticle(config, json_path).delete() - self.remove_empty_html_directories() + self.remove_empty_categories()