New hash for JS bundle

This commit is contained in:
Lucas Cimon 2019-02-10 08:49:07 +01:00
parent c9c730f727
commit 8f1db05670
No known key found for this signature in database
GPG Key ID: 08DA831E717571EE
5 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import itertools, re import itertools, os, re, sys
from hashlib import sha1 from hashlib import sha1
@ -18,8 +18,9 @@ def sed(filepath, pattern, value):
print('Generating CSS bundle') print('Generating CSS bundle')
short_hash = sha1(cat('static/main.css')).hexdigest()[:7] short_hash = sha1(cat('static/main.css')).hexdigest()[:7]
sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.css', '-SHORTSHA1-{}.css'.format(short_hash)) sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.css', '-SHORTSHA1-{}.css'.format(short_hash))
bundle_filename = 'bundle-SHORTSHA1-{}.css'.format(short_hash) css_bundle_filepath = 'static/bundle-SHORTSHA1-{}.css'.format(short_hash)
with open('static/' + bundle_filename, 'wb') as bundle: files_created = not os.path.exists(css_bundle_filepath)
with open(css_bundle_filepath, 'wb') as bundle:
bundle.write(cat('static/csslibs/uikit-2.27.4.min.css')) bundle.write(cat('static/csslibs/uikit-2.27.4.min.css'))
bundle.write(cat('static/csslibs/solarized-highlight.css')) bundle.write(cat('static/csslibs/solarized-highlight.css'))
bundle.write(cat('static/main.css')) bundle.write(cat('static/main.css'))
@ -28,9 +29,10 @@ print('Generating JS bundle')
short_hash = sha1(cat('static/js/social.js') + cat('static/js/filter-tags.js')).hexdigest()[:7] short_hash = sha1(cat('static/js/social.js') + cat('static/js/filter-tags.js')).hexdigest()[:7]
sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.js', '-SHORTSHA1-{}.js'.format(short_hash)) sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.js', '-SHORTSHA1-{}.js'.format(short_hash))
for SHARE, MG_FILTER_TAGS in itertools.product(range(2), repeat=2): for SHARE, MG_FILTER_TAGS in itertools.product(range(2), repeat=2):
bundle_filename = 'bundle-SHARE-{}-MG_FILTER_TAGS-{}-SHORTSHA1-{}.js'.format( js_bundle_filepath = 'static/bundle-SHARE-{}-MG_FILTER_TAGS-{}-SHORTSHA1-{}.js'.format(
SHARE, MG_FILTER_TAGS, short_hash) SHARE, MG_FILTER_TAGS, short_hash)
with open('static/' + bundle_filename, 'wb') as bundle: files_created |= not os.path.exists(js_bundle_filepath)
with open(js_bundle_filepath, 'wb') as bundle:
bundle.write(cat('static/jslibs/html5shiv-3.7.2.min.js')) bundle.write(cat('static/jslibs/html5shiv-3.7.2.min.js'))
bundle.write(cat('static/jslibs/jquery-1.10.2.min.js')) bundle.write(cat('static/jslibs/jquery-1.10.2.min.js'))
bundle.write(cat('static/jslibs/uikit-2.27.4.min.js')) bundle.write(cat('static/jslibs/uikit-2.27.4.min.js'))
@ -42,3 +44,6 @@ for SHARE, MG_FILTER_TAGS in itertools.product(range(2), repeat=2):
if MG_FILTER_TAGS: if MG_FILTER_TAGS:
bundle.write(cat('static/js/filter-tags.js')) bundle.write(cat('static/js/filter-tags.js'))
if files_created:
print('New bundle files were created', file=sys.stderr)
sys.exit(1)

View File

@ -97,6 +97,7 @@ if(e=u.split("-"),h=d[u]?d[u]:d["bottom-left"],this.justified&&this.justified.le
updateArticlesVisibility(); updateArticlesVisibility();
}; };
// This is a bit redundant with /tag/$tag.html pages, but is slightly more powerful as it allow to combine multiple filters
let queryParams = parseQuery(window.location.search); let queryParams = parseQuery(window.location.search);
for (let [qpName, qpValue] of Object.entries(queryParams)) { for (let [qpName, qpValue] of Object.entries(queryParams)) {
if (!qpValue) { continue; } if (!qpValue) { continue; }

View File

@ -343,6 +343,7 @@ $(document).ready(() => {
updateArticlesVisibility(); updateArticlesVisibility();
}; };
// This is a bit redundant with /tag/$tag.html pages, but is slightly more powerful as it allow to combine multiple filters
let queryParams = parseQuery(window.location.search); let queryParams = parseQuery(window.location.search);
for (let [qpName, qpValue] of Object.entries(queryParams)) { for (let [qpName, qpValue] of Object.entries(queryParams)) {
if (!qpValue) { continue; } if (!qpValue) { continue; }