open graph: Include multiple paragraphs in description tags.

This commit is contained in:
Rishi Gupta
2019-02-10 22:03:20 -08:00
committed by Tim Abbott
parent cd0e55cb95
commit e1f02dc6f2
3 changed files with 47 additions and 30 deletions

View File

@@ -460,9 +460,13 @@ class FinalizeOpenGraphDescription(MiddlewareMixin):
for tag in bs.find_all('div', class_="admonition"):
tag.clear()
# Find the first paragraph after that, and convert it from HTML to text.
first_paragraph_text = bs.find('p').text.replace('\n', ' ')
return first_paragraph_text
text = ''
for paragraph in bs.find_all('p'):
# .text converts it from HTML to text
text = text + paragraph.text.replace('\n', ' ') + ' '
if len(text) > 500:
return text.strip()
return text.strip()
def alter_content(content: bytes) -> bytes:
first_paragraph_text = get_content_description(content, request)