mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 13:01:08 +00:00
Give individual status page a title and OpenGraph description
This commit is contained in:
parent
fd0b1d90b0
commit
f7b4d9ea50
3 changed files with 52 additions and 7 deletions
|
@ -12,6 +12,8 @@ from django.db.models import Q
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.utils.translation import ngettext_lazy
|
||||||
from model_utils import FieldTracker
|
from model_utils import FieldTracker
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
|
||||||
|
@ -178,6 +180,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
"""you can't boost dms"""
|
"""you can't boost dms"""
|
||||||
return self.privacy in ["unlisted", "public"]
|
return self.privacy in ["unlisted", "public"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
"""title of the page when only this status is shown"""
|
||||||
|
return _("%(display_name)s's status") % {"display_name": self.user.display_name}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_description(self):
|
||||||
|
"""description of the page in meta tags when only this status is shown"""
|
||||||
|
return None
|
||||||
|
|
||||||
def to_replies(self, **kwargs):
|
def to_replies(self, **kwargs):
|
||||||
"""helper function for loading AP serialized replies to a status"""
|
"""helper function for loading AP serialized replies to a status"""
|
||||||
return self.to_ordered_collection(
|
return self.to_ordered_collection(
|
||||||
|
@ -332,6 +344,13 @@ class Comment(BookStatus):
|
||||||
|
|
||||||
activity_serializer = activitypub.Comment
|
activity_serializer = activitypub.Comment
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
return _("%(display_name)s's comment on %(book_title)s") % {
|
||||||
|
"display_name": self.user.display_name,
|
||||||
|
"book_title": self.book.title,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Quotation(BookStatus):
|
class Quotation(BookStatus):
|
||||||
"""like a review but without a rating and transient"""
|
"""like a review but without a rating and transient"""
|
||||||
|
@ -374,6 +393,13 @@ class Quotation(BookStatus):
|
||||||
|
|
||||||
activity_serializer = activitypub.Quotation
|
activity_serializer = activitypub.Quotation
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
return _("%(display_name)s's quote from %(book_title)s") % {
|
||||||
|
"display_name": self.user.display_name,
|
||||||
|
"book_title": self.book.title,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Review(BookStatus):
|
class Review(BookStatus):
|
||||||
"""a book review"""
|
"""a book review"""
|
||||||
|
@ -403,6 +429,13 @@ class Review(BookStatus):
|
||||||
"""indicate the book in question for mastodon (or w/e) users"""
|
"""indicate the book in question for mastodon (or w/e) users"""
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
return _("%(display_name)s's review of %(book_title)s") % {
|
||||||
|
"display_name": self.user.display_name,
|
||||||
|
"book_title": self.book.title,
|
||||||
|
}
|
||||||
|
|
||||||
activity_serializer = activitypub.Review
|
activity_serializer = activitypub.Review
|
||||||
pure_type = "Article"
|
pure_type = "Article"
|
||||||
|
|
||||||
|
@ -426,6 +459,18 @@ class ReviewRating(Review):
|
||||||
template = get_template("snippets/generated_status/rating.html")
|
template = get_template("snippets/generated_status/rating.html")
|
||||||
return template.render({"book": self.book, "rating": self.rating}).strip()
|
return template.render({"book": self.book, "rating": self.rating}).strip()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_description(self):
|
||||||
|
return ngettext_lazy(
|
||||||
|
"%(display_name)s rated %(book_title)s: %(display_rating).1f star",
|
||||||
|
"%(display_name)s rated %(book_title)s: %(display_rating).1f stars",
|
||||||
|
"display_rating",
|
||||||
|
) % {
|
||||||
|
"display_name": self.user.display_name,
|
||||||
|
"book_title": self.book.title,
|
||||||
|
"display_rating": self.rating,
|
||||||
|
}
|
||||||
|
|
||||||
activity_serializer = activitypub.Rating
|
activity_serializer = activitypub.Rating
|
||||||
pure_type = "Note"
|
pure_type = "Note"
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
{% load feed_page_tags %}
|
{% load feed_page_tags %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block title %}{{ title }}{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block opengraph %}
|
{% block opengraph %}
|
||||||
{% firstof status.book status.mention_books.first as book %}
|
|
||||||
{% if book %}
|
|
||||||
{% include 'snippets/opengraph.html' with image=preview %}
|
{% include 'snippets/opengraph.html' with image=preview %}
|
||||||
{% else %}
|
|
||||||
{% include 'snippets/opengraph.html' %}
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,8 @@ class Status(View):
|
||||||
"status": status,
|
"status": status,
|
||||||
"children": children,
|
"children": children,
|
||||||
"ancestors": ancestors,
|
"ancestors": ancestors,
|
||||||
|
"title": status.page_title,
|
||||||
|
"description": status.page_description,
|
||||||
"preview": preview,
|
"preview": preview,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue