Add ability to collapse "people also ask"

This adds a step in the filter process to wrap the "people also ask"
section in a <details> element, which automatically collapses the
contents of the section. Clicking/tapping the details element expands
the view as normal.

See #113
main
Ben Busby 2020-12-15 11:09:48 -05:00
parent 3978241d28
commit b695179c79
No known key found for this signature in database
GPG Key ID: 3B08611DF6E62ED2
3 changed files with 31 additions and 4 deletions

View File

@ -95,9 +95,26 @@ class Filter:
if not self.main_divs:
return
question_divs = [_ for _ in self.main_divs.find_all('div', recursive=False) if len(_.find_all('h2')) > 0]
question_divs = [_ for _ in self.main_divs.find_all(
'div', recursive=False
) if len(_.find_all('h2')) > 0]
if len(question_divs) == 0:
return
# Wrap section in details element to allow collapse/expand
details = BeautifulSoup(features='lxml').new_tag('details')
summary = BeautifulSoup(features='lxml').new_tag('summary')
summary.string = question_divs[0].find('h2').text
question_divs[0].find('h2').decompose()
details.append(summary)
question_divs[0].wrap(details)
for question_div in question_divs:
questions = [_ for _ in question_div.find_all('div', recursive=True) if _.text.endswith('?')]
questions = [_ for _ in question_div.find_all(
'div', recursive=True
) if _.text.endswith('?')]
for question in questions:
question['style'] = 'padding: 10px; font-style: italic;'

View File

@ -32,4 +32,9 @@
.autocomplete-active {
background-color: #685e79 !important;
color: #ffffff;
}
}
details summary {
padding: 10px;
font-weight: bold;
}

View File

@ -31,4 +31,9 @@
.autocomplete-active {
background-color: #685e79 !important;
color: #ffffff;
}
}
details summary {
padding: 10px;
font-weight: bold;
}