Fix authors in JSONFeed

Unfortunately, the only working validator I found can only validate live URLs
This commit is contained in:
rubenwardy 2024-07-02 20:55:01 +01:00
parent f8abcaa7c6
commit 9062f49992
4 changed files with 27 additions and 11 deletions

@ -50,7 +50,11 @@ def _get_new_packages_feed(feed_url: str) -> dict:
"language": "en", "language": "en",
"title": f"New: {package.title}", "title": f"New: {package.title}",
"content_html": render_markdown(package.desc) if package.desc else None, "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), "url": package.get_url("packages.view", absolute=True),
"summary": package.short_desc, "summary": package.short_desc,
"date_published": package.approved_at.isoformat(timespec="seconds") + "Z", "date_published": package.approved_at.isoformat(timespec="seconds") + "Z",
@ -72,7 +76,11 @@ def _get_releases_feed(query, feed_url: str):
"language": "en", "language": "en",
"title": f"{release.title} - {release.package.title}", "title": f"{release.title} - {release.package.title}",
"content_html": render_markdown(release.release_notes) if release.release_notes else None, "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), "url": release.package.get_url("packages.view_release", id=release.id, absolute=True),
"summary": release.summary, "summary": release.summary,
"date_published": release.created_at.isoformat(timespec="seconds") + "Z", "date_published": release.created_at.isoformat(timespec="seconds") + "Z",

@ -1099,11 +1099,11 @@ class PackageRelease(db.Model):
release_notes = db.Column(db.UnicodeText, nullable=True, default=None) release_notes = db.Column(db.UnicodeText, nullable=True, default=None)
@property @property
def summary(self) -> typing.Optional[str]: def summary(self) -> str:
if self.release_notes is None: if self.release_notes is None or \
return None self.release_notes.startswith("-") or \
if self.release_notes.startswith("-") or self.release_notes.startswith("*"): self.release_notes.startswith("*"):
return None return self.title
return self.release_notes.split("\n")[0] return self.release_notes.split("\n")[0]

@ -17,6 +17,7 @@
import datetime import datetime
import enum import enum
from flask import current_app
from flask_babel import lazy_gettext from flask_babel import lazy_gettext
from flask_login import UserMixin from flask_login import UserMixin
from sqlalchemy import desc, text from sqlalchemy import desc, text
@ -246,11 +247,17 @@ class User(db.Model, UserMixin):
def can_access_todo_list(self): def can_access_todo_list(self):
return Permission.APPROVE_NEW.check(self) or Permission.APPROVE_RELEASE.check(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: 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: 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: else:
from app.utils.gravatar import get_gravatar from app.utils.gravatar import get_gravatar
return get_gravatar(self.email or f"{self.username}@content.minetest.net") return get_gravatar(self.email or f"{self.username}@content.minetest.net")

@ -25,7 +25,8 @@
{{ post["content_html"] | escape }} {{ post["content_html"] | escape }}
</content> </content>
<author> <author>
<name>{{ post["author"] }}</name> <name>{{ post["author"]["name"] }}</name>
<uri>{{ post["author"]["url"] }}</uri>
</author> </author>
{% for tag in post["tags"] %} {% for tag in post["tags"] %}
<category term="{{ tag | escape }}" /> <category term="{{ tag | escape }}" />