Updated formatting and setup instructions
Switched encoding from utf-8 to unicode-escape in an effort to support multiple languages besides English. Updated image results page formatting to fix bad image links (added TODO for adding full res image link for each image result). Updated README to include libcurl and libssl install instructions for manual setup.main
parent
39c475af21
commit
0300eab6df
|
@ -42,6 +42,10 @@ If deploying manually:
|
|||
- Docker ([Windows](https://docs.docker.com/docker-for-windows/install/), [macOS](https://docs.docker.com/docker-for-mac/install/), [Ubuntu](https://docs.docker.com/engine/install/ubuntu/), [other Linux distros](https://docs.docker.com/engine/install/binaries/))
|
||||
- Only needed if you intend on deploying the app as a Docker image
|
||||
- [Python3](https://www.python.org/downloads/)
|
||||
- `libcurl4-openssl-dev` and `libssl-dev`
|
||||
- macOS: `brew install openssl curl-openssl`
|
||||
- Ubuntu: `sudo apt-get install -y libcurl4-openssl-dev libssl-dev`
|
||||
- Arch: `pacman -S curl openssl`
|
||||
- [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)
|
||||
- Only needed if you want to deploy the app to Heroku but don't want to use the deploy button shortcut.
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@ import urllib.parse as urlparse
|
|||
from urllib.parse import parse_qs
|
||||
|
||||
SKIP_ARGS = ['ref_src', 'utm']
|
||||
FULL_RES_IMG = '<br/><a href="{}">Full Image</a>'
|
||||
GOOG_IMG = '/images/branding/searchlogo/1x/googlelogo'
|
||||
LOGO_URL = GOOG_IMG + '_desk'
|
||||
BLANK_B64 = '''
|
||||
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkwAIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC
|
||||
'''
|
||||
|
||||
|
||||
class Filter:
|
||||
|
@ -68,9 +74,21 @@ class Filter:
|
|||
img_src = img['src']
|
||||
if img_src.startswith('//'):
|
||||
img_src = 'https:' + img_src
|
||||
elif img_src.startswith(GOOG_IMG):
|
||||
# Special rebranding for image search results
|
||||
if img_src.startswith(LOGO_URL):
|
||||
img['src'] = '/static/img/logo.png'
|
||||
img['height'] = 40
|
||||
else:
|
||||
img['src'] = BLANK_B64
|
||||
|
||||
continue
|
||||
|
||||
enc_src = Fernet(self.secret_key).encrypt(img_src.encode())
|
||||
img['src'] = '/tmp?image_url=' + enc_src.decode()
|
||||
# TODO: Non-mobile image results link to website instead of image
|
||||
# if not self.mobile:
|
||||
# img.append(BeautifulSoup(FULL_RES_IMG.format(img_src), 'html.parser'))
|
||||
|
||||
def update_styling(self, soup):
|
||||
# Remove unnecessary button(s)
|
||||
|
@ -126,6 +144,10 @@ class Filter:
|
|||
link_args = parse_qs(parsed_link.query)
|
||||
safe_args = {}
|
||||
|
||||
if len(link_args) == 0 and len(parsed_link) > 0:
|
||||
a['href'] = query_link
|
||||
continue
|
||||
|
||||
for arg in link_args.keys():
|
||||
if arg in SKIP_ARGS:
|
||||
continue
|
||||
|
|
|
@ -80,4 +80,4 @@ class Request:
|
|||
if return_bytes:
|
||||
return b_obj.getvalue()
|
||||
else:
|
||||
return b_obj.getvalue().decode('utf-8', 'ignore')
|
||||
return b_obj.getvalue().decode('unicode-escape', 'ignore')
|
||||
|
|
Loading…
Reference in New Issue