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

feat: rename published/updated_formatted to published/updated in templates

This commit is contained in:
Étienne Fildadut 2025-10-11 18:40:52 +02:00
parent 70b930a820
commit 174486ced8
4 changed files with 21 additions and 32 deletions

View file

@ -23,7 +23,7 @@ See read articles in the trash can.
Or ask feather to keep read articles: Or ask feather to keep read articles:
`server.only_sync_unread_articles = false` `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 ### Updating with the server

View file

@ -128,7 +128,7 @@ class GReaderArticle(Article):
self.feed_url = item_content.origin.html_url self.feed_url = item_content.origin.html_url
self.article_url = item_content.canonical[0].href self.article_url = item_content.canonical[0].href
self.compute_fields() self.compute_json_path()
class TTRSession(ClientSession): class TTRSession(ClientSession):
@ -227,4 +227,4 @@ class TTRArticle(Article):
self.language = article.lang self.language = article.lang
self.image_url = article.flavor_image self.image_url = article.flavor_image
self.compute_fields() self.compute_json_path()

View file

@ -41,10 +41,8 @@ reader = "reader"
# - id: article id (int | str) # - id: article id (int | str)
# - unread: if the article is unread (bool) - only makes sense if server.only_sync_unread_articles is false # - unread: if the article is unread (bool) - only makes sense if server.only_sync_unread_articles is false
# - title: article title (str) # - title: article title (str)
# - published: article publication time (timestamp) (int) # - published: article publication date and time (str)
# - published_formatted: article publication time (text) (str) # - updated: article publication date and time (str)
# - updated: article update time (timestamp) (int)
# - updated_formatted: article publication time (text) (str)
# - author: article author (str) # - author: article author (str)
# - summary: article summary (HTML) (str) # - summary: article summary (HTML) (str)
# - content: article content (HTML) (str) # - content: article content (HTML) (str)
@ -70,7 +68,7 @@ article_template = '''
<style>a{color:palevioletred; text-decoration:none;}</style> <style>a{color:palevioletred; text-decoration:none;}</style>
<article style="max-width:60rem; margin:auto; text-align:justify;"> <article style="max-width:60rem; margin:auto; text-align:justify;">
<p style="display:flex; flex-direction:row; justify-content:space-between;"> <p style="display:flex; flex-direction:row; justify-content:space-between;">
<span>{{ published_formatted }}</span> <span>{{ published }}</span>
<span> <span>
{% if feed_url %} {% if feed_url %}
<a href="{{ feed_url }}"> <a href="{{ feed_url }}">
@ -99,7 +97,7 @@ article_template = '''
# Filename template for generated HTML files. # Filename template for generated HTML files.
# The available fields are the same as for template. # The available fields are the same as for template.
# Can be set through the environment variable HTML_FILENAME_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. # Category directory name template for generated HTML files.
# Fields availables: # Fields availables:
# - id: category id (str | int) # - id: category id (str | int)

View file

@ -81,9 +81,6 @@ class Article(ABC):
# no default value # no default value
id: ArticleId # article unique id id: ArticleId # article unique id
category: Category # feed category 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 # 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) 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 # with default value
@ -132,14 +129,11 @@ class Article(ABC):
return html_path.relative_to(config.html_root) return html_path.relative_to(config.html_root)
def _get_template_dict(self) -> dict: def _get_template_dict(self) -> dict:
config = self.config
template_fields = ( template_fields = (
"id", "id",
"unread", "unread",
"title", "title",
"published",
"published_formatted",
"updated",
"updated_formatted",
"author", "author",
"summary", "summary",
"content", "content",
@ -153,29 +147,27 @@ class Article(ABC):
"image_url", "image_url",
) )
d = {field: getattr(self, field) for field in template_fields} 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() d["category"] = self.category.asdict()
return d return d
def compute_fields(self): def compute_json_path(self):
config = self.config
self.updated_formatted = format_datetime(config, self.updated)
self.published_formatted = format_datetime(config, self.published)
self.json_path = ( self.json_path = (
config.json_root self.config.json_root
/ f"{sha256(str(self.id).encode('utf-8')).hexdigest()}.json" / 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.""" """Write the JSON file associated with this article. Error if it already exists."""
if recompute_path:
self.compute_json_path()
stored_fields = ( stored_fields = (
"id", "id",
"unread", "unread",
"title", "title",
"published", "published",
"published_formatted",
"updated", "updated",
"updated_formatted",
"author", "author",
"summary", "summary",
"content", "content",
@ -210,13 +202,13 @@ class Article(ABC):
html_path = self.config.html_root / self.html_path html_path = self.config.html_root / self.html_path
return html_path.exists() 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. """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.""" 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 # Write HTML file for a JSON object
config = self.config 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()) self.html_path = str(self._get_html_path())
html_path = config.html_root / self.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(): if not ignore_deleted or html_path.exists():
html_path.unlink() html_path.unlink()
def write(self): def write(self, recompute_paths=False):
"""Write all the files associated with this article to disk.""" """Write all the files associated with this article to disk."""
self.write_html() self.write_html(recompute_path=recompute_paths)
self.write_json() self.write_json(recompute_path=recompute_paths)
def delete(self): def delete(self):
"""Delete all the files associated with this article.""" """Delete all the files associated with this article."""
@ -251,8 +243,7 @@ class Article(ABC):
def regenerate(self): def regenerate(self):
"""Delete and rewrite all the files associated with this article using to the latest configuration.""" """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.delete() # paths might change so we preemptively remove the old file
self.compute_fields() # recompute formatted datetime & paths from the current configuration self.write(recompute_paths=True) # rewrite JSON & HTML
self.write() # rewrite JSON & HTML
def was_updated(self, old_article: Article) -> bool: 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""" """Returns true if the article is different from a previous version in a way that would require regeneration"""