#!/bin/env python3
import os
import minify_html
if __name__ == '__main__':
HTML_SRC = ''
CSS_SRC = ''
# Preparing, check dirs
if not os.path.isdir('dist'):
os.mkdir('dist')
# Build HTML
with open('src/index.html') as file:
HTML_SRC = file.read()
minified = minify_html.minify(HTML_SRC, minify_js=True, do_not_minify_doctype=True, ensure_spec_compliant_unquoted_attribute_values=False, remove_processing_instructions=True)
# Fix minify_html bugs for W3C validator
minified = minified.replace('content=width=device-width,initial-scale=1', 'content="width=device-width, initial-scale=1"')
minified = minified.replace('icon"href', 'icon" href')
minified = minified.replace('«', '«')
minified = minified.replace('»', '»')
minified = minified.replace('-9999px;"alt', '-9999px;" alt')
HTML_SRC = minified
# Save HTML
with open('dist/index.html', 'w') as file:
file.write(HTML_SRC)
# Build CSS
with open('src/styles.css') as file:
CSS_SRC = file.read()
minified = minify_html.minify(CSS_SRC, minify_css=True, remove_processing_instructions=True)
CSS_SRC = minified
# Save CSS
with open('dist/styles.css', 'w') as file:
file.write(CSS_SRC)
# Copy other files
os.popen('cp src/favicon.ico src/humans.txt src/yandex_*.html dist/' )
# Make archive
os.popen('cd ./dist/; tar -czf ../dist.tar.gz *')
# os.popen('rm -rf ./dist/')