mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Improve Open Graph data for books and add it for lists
This commit is contained in:
parent
7f3551bab8
commit
89c1edac36
3 changed files with 31 additions and 1 deletions
|
@ -8,7 +8,7 @@
|
|||
{% block title %}{{ book|book_title }}{% endblock %}
|
||||
|
||||
{% block opengraph %}
|
||||
{% include 'snippets/opengraph.html' with image=book.preview_image %}
|
||||
{% include 'snippets/opengraph.html' with title=book.title description=book|book_description image=book.preview_image %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load list_page_tags %}
|
||||
|
||||
{% block title %}{{ list.name }}{% endblock %}
|
||||
|
||||
{% block opengraph %}
|
||||
{% include 'snippets/opengraph.html' with title=list|opengraph_title description=list|opengraph_description %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<header class="columns content is-mobile">
|
||||
<div class="column">
|
||||
|
|
25
bookwyrm/templatetags/list_page_tags.py
Normal file
25
bookwyrm/templatetags/list_page_tags.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
""" template filters for list page """
|
||||
from django import template
|
||||
from django.utils.translation import gettext_lazy as _, ngettext
|
||||
|
||||
from bookwyrm import models
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name="opengraph_title")
|
||||
def get_opengraph_title(book_list: models.List) -> str:
|
||||
"""Construct title for Open Graph"""
|
||||
return _("Book List: %(name)s") % {"name": book_list.name}
|
||||
|
||||
|
||||
@register.filter(name="opengraph_description")
|
||||
def get_opengraph_description(book_list: models.List) -> str:
|
||||
"""Construct description for Open Graph"""
|
||||
num_books = book_list.books.all().count()
|
||||
num_books_str = ngettext(
|
||||
"%(num)d book - by %(user)s", "%(num)d books - by %(user)s", num_books
|
||||
) % {"num": num_books, "user": book_list.user}
|
||||
|
||||
return f"{book_list.description} {num_books_str}"
|
Loading…
Reference in a new issue