diff --git a/README.md b/README.md
index a66d13d..d93052c 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ See read articles in the trash can.
Or ask feather to keep read articles:
`server.only_sync_unread_articles = false`
-`html.filename_template = "{% if unread %}☐{% else %}☑{% endif %} [{{ feed_title }}]\t{{ title }} ({{ published_formatted }}).html"`
+`html.filename_template = "{% if unread %}☐{% else %}☑{% endif %} [{{ feed_title }}]\t{{ title }} ({{ published }}).html"`
### Updating with the server
diff --git a/src/feather/client.py b/src/feather/client.py
index 5e5881d..7b45275 100644
--- a/src/feather/client.py
+++ b/src/feather/client.py
@@ -128,7 +128,7 @@ class GReaderArticle(Article):
self.feed_url = item_content.origin.html_url
self.article_url = item_content.canonical[0].href
- self.compute_fields()
+ self.compute_json_path()
class TTRSession(ClientSession):
@@ -227,4 +227,4 @@ class TTRArticle(Article):
self.language = article.lang
self.image_url = article.flavor_image
- self.compute_fields()
+ self.compute_json_path()
diff --git a/src/feather/config.default.toml b/src/feather/config.default.toml
index 0d92952..56455f9 100644
--- a/src/feather/config.default.toml
+++ b/src/feather/config.default.toml
@@ -41,10 +41,8 @@ reader = "reader"
# - 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)
-# - updated: article update time (timestamp) (int)
-# - updated_formatted: article publication time (text) (str)
+# - published: article publication date and time (str)
+# - updated: article publication date and time (str)
# - author: article author (str)
# - summary: article summary (HTML) (str)
# - content: article content (HTML) (str)
@@ -70,7 +68,7 @@ article_template = '''
- {{ published_formatted }}
+ {{ published }}
{% if feed_url %}
@@ -99,7 +97,7 @@ article_template = '''
# Filename template for generated HTML files.
# The available fields are the same as for template.
# Can be set through the environment variable HTML_FILENAME_TEMPLATE.
-filename_template = "[{{ feed_title }}]\t{{ title }} ({{ published_formatted }}).html"
+filename_template = "[{{ feed_title }}]\t{{ title }} ({{ published }}).html"
# Category directory name template for generated HTML files.
# Fields availables:
# - id: category id (str | int)
diff --git a/src/feather/data.py b/src/feather/data.py
index 5cb9591..91948a1 100644
--- a/src/feather/data.py
+++ b/src/feather/data.py
@@ -81,9 +81,6 @@ class Article(ABC):
# no default value
id: ArticleId # article unique id
category: Category # feed category
- # no default value, computed by compute_fields
- published_formatted: str # article publication time (text)
- updated_formatted: str # article publication time (text)
# no default value, computed on save_html
html_path: str = None # html path, relative to the html_root directory (None will force it to be recomputed on next save_html)
# with default value
@@ -132,14 +129,11 @@ class Article(ABC):
return html_path.relative_to(config.html_root)
def _get_template_dict(self) -> dict:
+ config = self.config
template_fields = (
"id",
"unread",
"title",
- "published",
- "published_formatted",
- "updated",
- "updated_formatted",
"author",
"summary",
"content",
@@ -153,29 +147,27 @@ class Article(ABC):
"image_url",
)
d = {field: getattr(self, field) for field in template_fields}
+ d["published"] = format_datetime(config, self.updated)
+ d["updated"] = format_datetime(config, self.published)
d["category"] = self.category.asdict()
return d
- def compute_fields(self):
- config = self.config
- self.updated_formatted = format_datetime(config, self.updated)
- self.published_formatted = format_datetime(config, self.published)
+ def compute_json_path(self):
self.json_path = (
- config.json_root
+ self.config.json_root
/ f"{sha256(str(self.id).encode('utf-8')).hexdigest()}.json"
)
- self.html_path = None
- def write_json(self):
+ def write_json(self, recompute_path=False):
"""Write the JSON file associated with this article. Error if it already exists."""
+ if recompute_path:
+ self.compute_json_path()
stored_fields = (
"id",
"unread",
"title",
"published",
- "published_formatted",
"updated",
- "updated_formatted",
"author",
"summary",
"content",
@@ -210,13 +202,13 @@ class Article(ABC):
html_path = self.config.html_root / self.html_path
return html_path.exists()
- def write_html(self):
+ def write_html(self, recompute_path=False):
"""Write the HTML file associated with this article. Error if it already exists.
Note: this may recompute html_path, which is saved into the JSON - so make sure to save the JSON file _after_ the HTML file."""
# Write HTML file for a JSON object
config = self.config
- if self.html_path is None:
+ if self.html_path is None or recompute_path:
self.html_path = str(self._get_html_path())
html_path = config.html_root / self.html_path
@@ -238,10 +230,10 @@ class Article(ABC):
if not ignore_deleted or html_path.exists():
html_path.unlink()
- def write(self):
+ def write(self, recompute_paths=False):
"""Write all the files associated with this article to disk."""
- self.write_html()
- self.write_json()
+ self.write_html(recompute_path=recompute_paths)
+ self.write_json(recompute_path=recompute_paths)
def delete(self):
"""Delete all the files associated with this article."""
@@ -251,8 +243,7 @@ class Article(ABC):
def regenerate(self):
"""Delete and rewrite all the files associated with this article using to the latest configuration."""
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
+ self.write(recompute_paths=True) # rewrite JSON & HTML
def was_updated(self, old_article: Article) -> bool:
"""Returns true if the article is different from a previous version in a way that would require regeneration"""