mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-27 10:09:32 +00:00
fix: proper updating of read articles
This commit is contained in:
parent
a587340865
commit
e271b3776a
3 changed files with 7 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
@ -150,6 +150,10 @@ class Article(ABC):
|
|||
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:
|
||||
self.config = config
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue