encode css as base64 instead
This commit is contained in:
parent
edd356e437
commit
278d7b14f2
1 changed files with 5 additions and 6 deletions
11
owug.py
11
owug.py
|
@ -51,9 +51,12 @@ for item in imgs:
|
||||||
head = soup.find_all('link', rel='stylesheet')
|
head = soup.find_all('link', rel='stylesheet')
|
||||||
for item in head:
|
for item in head:
|
||||||
url = absolute_url(item.attrs['href'], domain_thing)
|
url = absolute_url(item.attrs['href'], domain_thing)
|
||||||
|
css_mime_type = requests.head(url).headers['Content-Type']
|
||||||
style_data = requests.get(url).content.decode()
|
style_data = requests.get(url).content.decode()
|
||||||
|
|
||||||
# hardcode fonts
|
# hardcode fonts
|
||||||
|
# i am encoding a font in base64 in css in base64 in html
|
||||||
|
# this program is unholy
|
||||||
index = -1
|
index = -1
|
||||||
while True:
|
while True:
|
||||||
index = style_data.find('url(', index + 1)
|
index = style_data.find('url(', index + 1)
|
||||||
|
@ -70,16 +73,12 @@ for item in head:
|
||||||
|
|
||||||
style_data = style_data.replace(original_url, new_url)
|
style_data = style_data.replace(original_url, new_url)
|
||||||
|
|
||||||
head = soup.find('head')
|
item.attrs['href'] = f'data:{css_mime_type};base64,{b64encode_as_string(bytes(style_data, 'utf-8'))}'
|
||||||
new_tag = soup.new_tag('style')
|
|
||||||
new_tag.string = style_data
|
|
||||||
soup.head.append(new_tag)
|
|
||||||
item.decompose()
|
|
||||||
|
|
||||||
# change relative links to absolute
|
# change relative links to absolute
|
||||||
links = soup.find_all('link')
|
links = soup.find_all('link')
|
||||||
for item in links:
|
for item in links:
|
||||||
if 'icon' not in item.attrs['rel']:
|
if 'stylesheet' not in item.attrs['rel'] and 'icon' not in item.attrs['rel']:
|
||||||
item.attrs['href'] = absolute_url(item.attrs['href'], domain_thing)
|
item.attrs['href'] = absolute_url(item.attrs['href'], domain_thing)
|
||||||
|
|
||||||
with open(sys.argv[2], 'wt') as f:
|
with open(sys.argv[2], 'wt') as f:
|
||||||
|
|
Loading…
Reference in a new issue