diff --git a/src/feather/config.default.toml b/src/feather/config.default.toml index 45e785b..11294a2 100644 --- a/src/feather/config.default.toml +++ b/src/feather/config.default.toml @@ -39,6 +39,7 @@ reader = "reader" # HTML template used for generating article HTML files. All templates are Jinja2 templates. # Available fields: # - id: article id (int | str) +# - unread: if the article is unread (bool) - only makes sense if server.only_sync_unread_articles is false # - title: article title (str) # - published: article publication time (timestamp) (int) # - published_formatted: article publication time (text) (str) diff --git a/src/feather/data.py b/src/feather/data.py index abb3e99..d1d786c 100644 --- a/src/feather/data.py +++ b/src/feather/data.py @@ -115,7 +115,7 @@ class Article(ABC): article_json = { field: getattr(self, field) for field in stored_fields } article_json["category"] = self.category.asdict() if self.json_path.exists(): - raise Exception + raise Exception(f"Unexpectedly tried to overwrite article data for {self.json_path}") with self.json_path.open("w") as f: json.dump(article_json, f) def delete_json(self): @@ -149,6 +149,10 @@ class Article(ABC): self.delete() # paths might change so we preemptively remove the old file self.compute_fields() # recompute formatted datetime & paths from the current configuration self.write() # rewrite JSON & HTML + + def was_updated(self, old_article: Article): + """Returns true if the article is different from a previous version in a way that would require regeneration""" + return old_article.get_template_dict() != self.get_template_dict() class FileArticle(Article): def __init__(self, config: Config, json_path: Path) -> Article: diff --git a/src/feather/feather.py b/src/feather/feather.py index ede8949..928e45b 100755 --- a/src/feather/feather.py +++ b/src/feather/feather.py @@ -61,7 +61,6 @@ class FeatherApp: html_path = config.html_root / article.html_path if not html_path.exists(): to_mark_as_read.append(article.id) - article.delete() marked_as_read += 1 for i in range(0, len(to_mark_as_read), config.articles_per_query): @@ -100,7 +99,7 @@ class FeatherApp: new_articles += 1 else: old_article = FileArticle(config, json_path) - if article.updated > old_article.updated: + if article.was_updated(old_article): old_article.delete() article.write() updated_articles += 1