This commit is contained in:
caandt 2024-10-01 00:08:13 -05:00
parent e8d2f67a40
commit 50365401d3

View file

@ -23,12 +23,10 @@ def glob_all_to(src, dst):
else: else:
yield page, Path(f'{dst}/{page.relative_to(src)}') yield page, Path(f'{dst}/{page.relative_to(src)}')
def path_write(path, text): def minify(html):
path.parent.mkdir(exist_ok=True, parents=True)
if minimal and path.suffix == '.html':
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import minify_html import minify_html
soup = BeautifulSoup(text, 'html.parser') soup = BeautifulSoup(html, 'html.parser')
for div in soup.find_all('div'): for div in soup.find_all('div'):
div.unwrap() div.unwrap()
tab = False tab = False
@ -45,8 +43,12 @@ def path_write(path, text):
soup.insert(1, tab) soup.insert(1, tab)
for tag in soup.find_all(True): for tag in soup.find_all(True):
tag.attrs = {k: v for k, v in tag.attrs.items() if k != 'class'} tag.attrs = {k: v for k, v in tag.attrs.items() if k != 'class'}
t = minify_html.minify(str(soup)) return minify_html.minify(str(soup))
path.write_text(t)
def path_write(path, text):
path.parent.mkdir(exist_ok=True, parents=True)
if minimal and path.suffix == '.html':
path.write_text(minify(text))
else: else:
path.write_text(text) path.write_text(text)