add font support

This commit is contained in:
askiiart 2025-01-04 18:39:13 -06:00
parent 84e399c087
commit 64d3238745
Signed by untrusted user who does not match committer: askiiart
GPG key ID: 6A32977DAF31746A
2 changed files with 18 additions and 4 deletions

View file

@ -32,10 +32,6 @@ python3 owug.py 'https://example.com' 'out.html'
OWUG is licensed under `GPL-3.0-only`.
## TODO
- Add font support
---
There's definitely not a secret patch to add JS support [here](/secret-js.patch).

18
owug.py
View file

@ -52,6 +52,24 @@ head = soup.find_all('link', rel='stylesheet')
for item in head:
url = absolute_url(item.attrs['href'], domain_thing)
style_data = requests.get(url).content.decode()
# hardcode fonts
index = -1
while True:
index = style_data.find('url(', index + 1)
if index == -1:
break
original_url = style_data[index + 5 : style_data.find(')', index) - 1]
absolute = absolute_url(
original_url, domain_thing
)
mime_type = requests.head(absolute).headers['Content-Type']
as_base64 = b64encode_as_string(requests.get(absolute).content)
new_url = f'data:{mime_type};base64,{as_base64}'
style_data = style_data.replace(original_url, new_url)
head = soup.find('head')
new_tag = soup.new_tag('style')
new_tag.string = style_data