Generator script
parent
adb21ffe5c
commit
df8c30f5b4
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Install updates
|
||||||
|
pip3 install --upgrade --user pip &&
|
||||||
|
pip3 install --upgrade --user pelican markdown htmlmin &&
|
||||||
|
|
||||||
|
# Clean and generate
|
||||||
|
(rm -rf output || true) &&
|
||||||
|
python3 -c "import pelican; pelican.main()" content &&
|
||||||
|
|
||||||
|
# Optimize
|
||||||
|
tools/cssfix.py output/theme/css/* &&
|
||||||
|
(
|
||||||
|
for i in `find output -wholename "*.html"`
|
||||||
|
do
|
||||||
|
htmlmin -c -s "$i" "$i" || exit 1
|
||||||
|
done
|
||||||
|
) &&
|
||||||
|
|
||||||
|
# Compress
|
||||||
|
(
|
||||||
|
for i in `find output -wholename "*.css" -or -wholename "*.js" -or -wholename "*.html"`
|
||||||
|
do
|
||||||
|
(gzip --best --keep "$i" && brotli --best --keep "$i") ||
|
||||||
|
(echo ERROR in file $i; exit 1) || exit 1
|
||||||
|
done
|
||||||
|
)
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# Install cssutils
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
subprocess.check_call(("pip", "install", "--upgrade", "--user", "cssutils"))
|
||||||
|
|
||||||
|
# Run tool
|
||||||
|
import base64
|
||||||
|
import cssutils
|
||||||
|
import cssutils.scripts
|
||||||
|
import mimetypes
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
for i in sys.argv[1:]:
|
||||||
|
file = cssutils.parseFile(i)
|
||||||
|
|
||||||
|
# Inline urls
|
||||||
|
def urlInlineFunction(url):
|
||||||
|
tmp = os.path.join(os.path.split(i)[0], url)
|
||||||
|
try:
|
||||||
|
urlType = mimetypes.guess_type(tmp)[0]
|
||||||
|
return (b"data:" + urlType.encode() + b";base64," + base64.encodebytes(open(tmp, "rb").read()).replace(b"\n", b"")).decode()
|
||||||
|
except Exception as e:
|
||||||
|
print("Can't use file: " + repr(url))
|
||||||
|
print(e)
|
||||||
|
return url
|
||||||
|
cssutils.replaceUrls(file, urlInlineFunction, True)
|
||||||
|
|
||||||
|
with open(i, "wb") as tmp:
|
||||||
|
tmp.write(cssutils.scripts.csscombine(path=i, cssText=file.cssText, minify=True))
|
Loading…
Reference in New Issue