Skip to content

Commit

Permalink
Fix authors in JSONFeed
Browse files Browse the repository at this point in the history
Unfortunately, the only working validator I found can only validate live URLs
  • Loading branch information
rubenwardy committed Jul 2, 2024
1 parent f8abcaa commit 9062f49
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
12 changes: 10 additions & 2 deletions app/blueprints/feeds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def _get_new_packages_feed(feed_url: str) -> dict:
"language": "en",
"title": f"New: {package.title}",
"content_html": render_markdown(package.desc) if package.desc else None,
"author": package.author.display_name,
"author": {
"name": package.author.display_name,
"avatar": package.author.get_profile_pic_url(absolute=True),
"url": abs_url_for("users.profile", username=package.author.username),
},
"url": package.get_url("packages.view", absolute=True),
"summary": package.short_desc,
"date_published": package.approved_at.isoformat(timespec="seconds") + "Z",
Expand All @@ -72,7 +76,11 @@ def _get_releases_feed(query, feed_url: str):
"language": "en",
"title": f"{release.title} - {release.package.title}",
"content_html": render_markdown(release.release_notes) if release.release_notes else None,
"author": release.package.author.display_name,
"author": {
"name": release.package.author.display_name,
"avatar": release.package.author.get_profile_pic_url(absolute=True),
"url": abs_url_for("users.profile", username=release.package.author.username),
},
"url": release.package.get_url("packages.view_release", id=release.id, absolute=True),
"summary": release.summary,
"date_published": release.created_at.isoformat(timespec="seconds") + "Z",
Expand Down
10 changes: 5 additions & 5 deletions app/models/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,11 @@ class PackageRelease(db.Model):
release_notes = db.Column(db.UnicodeText, nullable=True, default=None)

@property
def summary(self) -> typing.Optional[str]:
if self.release_notes is None:
return None
if self.release_notes.startswith("-") or self.release_notes.startswith("*"):
return None
def summary(self) -> str:
if self.release_notes is None or \
self.release_notes.startswith("-") or \
self.release_notes.startswith("*"):
return self.title

return self.release_notes.split("\n")[0]

Expand Down
13 changes: 10 additions & 3 deletions app/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import datetime
import enum

from flask import current_app
from flask_babel import lazy_gettext
from flask_login import UserMixin
from sqlalchemy import desc, text
Expand Down Expand Up @@ -246,11 +247,17 @@ def __init__(self, username=None, active=False, email=None, password=None):
def can_access_todo_list(self):
return Permission.APPROVE_NEW.check(self) or Permission.APPROVE_RELEASE.check(self)

def get_profile_pic_url(self):
def get_profile_pic_url(self, absolute: bool = False):
if self.profile_pic:
return self.profile_pic
if absolute:
return current_app.config["BASE_URL"] + self.profile_pic
else:
return self.profile_pic
elif self.rank == UserRank.BOT:
return "/static/bot_avatar.png"
if absolute:
return current_app.config["BASE_URL"] + "/static/bot_avatar.png"
else:
return "/static/bot_avatar.png"
else:
from app.utils.gravatar import get_gravatar
return get_gravatar(self.email or f"{self.username}@content.minetest.net")
Expand Down
3 changes: 2 additions & 1 deletion app/templates/feeds/json_to_atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
{{ post["content_html"] | escape }}
</content>
<author>
<name>{{ post["author"] }}</name>
<name>{{ post["author"]["name"] }}</name>
<uri>{{ post["author"]["url"] }}</uri>
</author>
{% for tag in post["tags"] %}
<category term="{{ tag | escape }}" />
Expand Down

0 comments on commit 9062f49

Please sign in to comment.