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')
|
||||
for item in head:
|
||||
url = absolute_url(item.attrs['href'], domain_thing)
|
||||
css_mime_type = requests.head(url).headers['Content-Type']
|
||||
style_data = requests.get(url).content.decode()
|
||||
|
||||
# hardcode fonts
|
||||
# i am encoding a font in base64 in css in base64 in html
|
||||
# this program is unholy
|
||||
index = -1
|
||||
while True:
|
||||
index = style_data.find('url(', index + 1)
|
||||
|
@ -70,16 +73,12 @@ for item in head:
|
|||
|
||||
style_data = style_data.replace(original_url, new_url)
|
||||
|
||||
head = soup.find('head')
|
||||
new_tag = soup.new_tag('style')
|
||||
new_tag.string = style_data
|
||||
soup.head.append(new_tag)
|
||||
item.decompose()
|
||||
item.attrs['href'] = f'data:{css_mime_type};base64,{b64encode_as_string(bytes(style_data, 'utf-8'))}'
|
||||
|
||||
# change relative links to absolute
|
||||
links = soup.find_all('link')
|
||||
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)
|
||||
|
||||
with open(sys.argv[2], 'wt') as f:
|
||||
|
|
Loading…
Reference in a new issue