mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 21:11:16 +00:00
Merge pull request #268 from mouse-reeve/show-hide-text
Show/hide toggle for long book descriptions
This commit is contained in:
commit
6bd8a19e4a
3 changed files with 40 additions and 3 deletions
|
@ -230,7 +230,7 @@ def handle_create(activity):
|
|||
if hasattr(activity, 'inReplyToBook'):
|
||||
book_urls.append(activity.inReplyToBook)
|
||||
if hasattr(activity, 'tag'):
|
||||
book_urls += [t.href for t in activity.tag if t.type == 'Book']
|
||||
book_urls += [t['href'] for t in activity.tag if t['type'] == 'Book']
|
||||
for remote_id in book_urls:
|
||||
books_manager.get_or_create_book(remote_id)
|
||||
|
||||
|
|
|
@ -1,2 +1,20 @@
|
|||
<blockquote class="content">{% if book.description %}{{ book.description }}{% elif book.parent_work.description %}{{ book.parent_work.description }}{% endif %}</blockquote>
|
||||
|
||||
{% load fr_display %}
|
||||
{% with book|book_description as full %}
|
||||
{% with full|text_overflow as trimmed %}
|
||||
{% if trimmed != full %}
|
||||
<div>
|
||||
<input type="radio" name="show-hide-{{ book.id }}" id="show-{{ book.id }}" class="toggle-control" checked>
|
||||
<blockquote class="content toggle-content hidden">{{ trimmed }}
|
||||
<label class="button is-small" for="hide-{{ book.id }}">show more</label></blockquote>
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" name="show-hide-{{ book.id }}" id="hide-{{ book.id }}" class="toggle-control">
|
||||
<blockquote class="content toggle-content hidden">{{ full }}
|
||||
<label class="button is-small" for="show-{{ book.id }}">show less</label></blockquote>
|
||||
</div>
|
||||
{% else %}
|
||||
<blockquote class="content">{{ full }}
|
||||
</blockquote>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -106,6 +106,25 @@ def get_edition_info(book):
|
|||
return ', '.join(i for i in items if i)
|
||||
|
||||
|
||||
@register.filter(name='book_description')
|
||||
def get_book_description(book):
|
||||
''' use the work's text if the book doesn't have it '''
|
||||
return book.description or book.parent_work.description
|
||||
|
||||
|
||||
@register.filter(name='text_overflow')
|
||||
def text_overflow(text):
|
||||
''' dont' let book descriptions run for ages '''
|
||||
char_max = 500
|
||||
if len(text) < char_max:
|
||||
return text
|
||||
|
||||
trimmed = text[:char_max]
|
||||
# go back to the last space
|
||||
trimmed = ' '.join(trimmed.split(' ')[:-1])
|
||||
return trimmed + '...'
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def shelve_button_identifier(context, book):
|
||||
''' check what shelf a user has a book on, if any '''
|
||||
|
|
Loading…
Reference in a new issue