From 9bc5ccbbdcd24cd9c94159570e33b14317b849c3 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 11 Apr 2023 14:05:46 +0100 Subject: [PATCH] Don't include the first tangent in the content HTML This prevents it being used as part of the summary, which in the case of updates looks strange. --- website/common/streamfield.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/website/common/streamfield.py b/website/common/streamfield.py index e348196..fa446d5 100644 --- a/website/common/streamfield.py +++ b/website/common/streamfield.py @@ -106,9 +106,14 @@ def get_content_html(html: str) -> str: if not isinstance(block, IGNORE_PLAINTEXT_BLOCKS) ] - return str( - BeautifulSoup(html, "lxml", parse_only=SoupStrainer(class_=block_classes)) - ) + soup = BeautifulSoup(html, "lxml", parse_only=SoupStrainer(class_=block_classes)) + + # If the first block is a tangent, remove it + first_block = soup.find("div", class_=block_classes) + if first_block and first_block.attrs["class"][0].endswith("tangent"): + first_block.extract() + + return str(soup) def add_heading_anchors(html: str) -> str: