From 64dbcf16ed7a9000e9f4a1719a809c58839ac9e1 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Fri, 17 Dec 2021 17:56:57 +0100 Subject: [PATCH] trim to 50 words instead of chars Closes https://git.vvvvvvaria.org/simoon/temporary-indexing/issues/1. --- temp_index.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/temp_index.py b/temp_index.py index 95c96ab..38e2e05 100644 --- a/temp_index.py +++ b/temp_index.py @@ -12,6 +12,7 @@ from reportlab.pdfgen import canvas from reportlab.platypus import PageBreak, Paragraph, SimpleDocTemplate, Spacer CWD = Path().resolve() +NUM_WORDS_COMMENT = 50 from html.parser import HTMLParser from io import StringIO @@ -64,12 +65,7 @@ def select_fields(fields, content, styles, book): content.append(Spacer(1, 12)) if "comments" in fields: - comments = ", ".join( - [ - shorten(comment.text, width=50, placeholder="...") - for comment in book.comments - ] - ) + comments = " ".join([c.text for c in book.comments]).split()[:NUM_WORDS_COMMENT] tag = "{}".format(comments) pcomments = Paragraph(strip_tags(tag)) content.append(pcomments)