Add WHOOGLE_MINIMAL to docs, tweak min mode logic

Activating minimal mode should also remove all collapsed sections, if
any are found.

WHOOGLE_MINIMAL now documented in readme and app.json (for heroku).
main
Ben Busby 2021-10-26 10:38:20 -06:00
parent 543f2b2a01
commit 90441b2668
No known key found for this signature in database
GPG Key ID: 339B7B7EB5333D14
3 changed files with 19 additions and 6 deletions

View File

@ -1,4 +1,4 @@
![Whoogle Search](https://raw.githubusercontent.com/benbusby/whoogle-search/main/docs/banner.png) ![Whoogle Search](docs/banner.png)
[![Latest Release](https://img.shields.io/github/v/release/benbusby/whoogle-search)](https://github.com/benbusby/shoogle/releases) [![Latest Release](https://img.shields.io/github/v/release/benbusby/whoogle-search)](https://github.com/benbusby/shoogle/releases)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@ -321,6 +321,7 @@ There are a few optional environment variables available for customizing a Whoog
| WHOOGLE_ALT_TL | The Google Translate alternative to use. This is used for all "translate ____" searches. | | WHOOGLE_ALT_TL | The Google Translate alternative to use. This is used for all "translate ____" searches. |
| WHOOGLE_ALT_MD | The medium.com alternative to use when site alternatives are enabled in the config. | | WHOOGLE_ALT_MD | The medium.com alternative to use when site alternatives are enabled in the config. |
| WHOOGLE_AUTOCOMPLETE | Controls visibility of autocomplete/search suggestions. Default on -- use '0' to disable | | WHOOGLE_AUTOCOMPLETE | Controls visibility of autocomplete/search suggestions. Default on -- use '0' to disable |
| WHOOGLE_MINIMAL | Remove everything except basic result cards from all search queries. |
### Config Environment Variables ### Config Environment Variables
These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time.
@ -505,7 +506,7 @@ A lot of the app currently piggybacks on Google's existing support for fetching
## Screenshots ## Screenshots
#### Desktop #### Desktop
![Whoogle Desktop](https://raw.githubusercontent.com/benbusby/whoogle-search/main/docs/screenshot_desktop.jpg) ![Whoogle Desktop](docs/screenshot_desktop.jpg)
#### Mobile #### Mobile
![Whoogle Mobile](https://raw.githubusercontent.com/benbusby/whoogle-search/main/docs/screenshot_mobile.jpg) ![Whoogle Mobile](docs/screenshot_mobile.jpg)

View File

@ -75,6 +75,11 @@
"value": "scribe.rip", "value": "scribe.rip",
"required": false "required": false
}, },
"WHOOGLE_MINIMAL": {
"description": "Remove everything except basic result cards from all search queries (set to 1 or leave blank)",
"value": "",
"required": false
},
"WHOOGLE_CONFIG_COUNTRY": { "WHOOGLE_CONFIG_COUNTRY": {
"description": "[CONFIG] The country to use for restricting search results (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/countries.json)", "description": "[CONFIG] The country to use for restricting search results (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/countries.json)",
"value": "", "value": "",

View File

@ -1,4 +1,5 @@
from app.request import VALID_PARAMS, MAPS_URL from app.request import VALID_PARAMS, MAPS_URL
from app.utils.misc import read_config_bool
from app.utils.results import * from app.utils.results import *
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from bs4.element import ResultSet, Tag from bs4.element import ResultSet, Tag
@ -8,7 +9,6 @@ import re
import urllib.parse as urlparse import urllib.parse as urlparse
from urllib.parse import parse_qs from urllib.parse import parse_qs
import os import os
from app.utils.misc import read_config_bool
def extract_q(q_str: str, href: str) -> str: def extract_q(q_str: str, href: str) -> str:
@ -173,6 +173,8 @@ class Filter:
Returns: Returns:
None (The soup object is modified directly) None (The soup object is modified directly)
""" """
minimal_mode = read_config_bool('WHOOGLE_MINIMAL')
def pull_child_divs(result_div: BeautifulSoup): def pull_child_divs(result_div: BeautifulSoup):
try: try:
return result_div.findChildren( return result_div.findChildren(
@ -188,7 +190,7 @@ class Filter:
# Loop through results and check for the number of child divs in each # Loop through results and check for the number of child divs in each
for result in self.main_divs: for result in self.main_divs:
result_children = pull_child_divs(result) result_children = pull_child_divs(result)
if read_config_bool('WHOOGLE_MINIMAL'): if minimal_mode:
if len(result_children) in (1, 3): if len(result_children) in (1, 3):
continue continue
else: else:
@ -212,13 +214,18 @@ class Filter:
while not parent and idx < len(result_children): while not parent and idx < len(result_children):
parent = result_children[idx].parent parent = result_children[idx].parent
idx += 1 idx += 1
details = BeautifulSoup(features='html.parser').new_tag('details') details = BeautifulSoup(features='html.parser').new_tag('details')
summary = BeautifulSoup(features='html.parser').new_tag('summary') summary = BeautifulSoup(features='html.parser').new_tag('summary')
summary.string = label summary.string = label
details.append(summary) details.append(summary)
if parent: if parent and not minimal_mode:
parent.wrap(details) parent.wrap(details)
elif parent and minimal_mode:
# Remove parent element from document if "minimal mode" is
# enabled
parent.decompose()
def update_element_src(self, element: Tag, mime: str) -> None: def update_element_src(self, element: Tag, mime: str) -> None:
"""Encrypts the original src of an element and rewrites the element src """Encrypts the original src of an element and rewrites the element src