Fixing short sha1 computing

This commit is contained in:
Lucas Cimon 2017-12-05 00:03:59 +01:00
parent c1b90abf41
commit ae47bb989a
No known key found for this signature in database
GPG Key ID: 6AF36E0DE97FE852
13 changed files with 8 additions and 7 deletions

View File

@ -47,6 +47,7 @@ Features
* Share buttons built with share urls. * Share buttons built with share urls.
* Custom footer notice. * Custom footer notice.
* W3C-Validated HTML * W3C-Validated HTML
* Home page images lazy-loading
Install Install
------- -------

View File

@ -16,6 +16,8 @@ def sed(filepath, pattern, value):
# Generating CSS bundle # Generating CSS bundle
short_hash = sha1(cat('static/css/main.css')).hexdigest()[:7]
sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.css', '-SHORTSHA1-{}.css'.format(short_hash))
for DISABLE_SEARCH in range(2): for DISABLE_SEARCH in range(2):
bundle = b'' bundle = b''
bundle += cat('static/csslibs/uikit-2.27.4.min.css') bundle += cat('static/csslibs/uikit-2.27.4.min.css')
@ -24,13 +26,13 @@ for DISABLE_SEARCH in range(2):
bundle += cat('static/csslibs/tipuesearch.css') bundle += cat('static/csslibs/tipuesearch.css')
bundle += cat('static/csslibs/solarized-highlight.css') bundle += cat('static/csslibs/solarized-highlight.css')
bundle += cat('static/css/main.css') bundle += cat('static/css/main.css')
short_hash = sha1(bundle).hexdigest()[:7]
bundle_filename = 'bundle-DISABLE_SEARCH-{}-SHORTSHA1-{}.css'.format(DISABLE_SEARCH, short_hash) bundle_filename = 'bundle-DISABLE_SEARCH-{}-SHORTSHA1-{}.css'.format(DISABLE_SEARCH, short_hash)
with open('static/' + bundle_filename, 'wb') as bundle_file: with open('static/' + bundle_filename, 'wb') as bundle_file:
bundle_file.write(bundle) bundle_file.write(bundle)
sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.css', '-SHORTSHA1-{}.css'.format(short_hash))
# Generating JS bundle # Generating JS bundle
short_hash = sha1(cat('static/js/enable-search.js') + 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))
for DISABLE_SEARCH, SHARE, MG_FILTER_TAGS in itertools.product(range(2), repeat=3): for DISABLE_SEARCH, SHARE, MG_FILTER_TAGS in itertools.product(range(2), repeat=3):
bundle = b'' bundle = b''
bundle += cat('static/jslibs/html5shiv-3.7.2.min.js') bundle += cat('static/jslibs/html5shiv-3.7.2.min.js')
@ -48,9 +50,7 @@ for DISABLE_SEARCH, SHARE, MG_FILTER_TAGS in itertools.product(range(2), repeat=
bundle += cat('static/js/social.js') bundle += cat('static/js/social.js')
if MG_FILTER_TAGS: if MG_FILTER_TAGS:
bundle += cat('static/js/filter-tags.js') bundle += cat('static/js/filter-tags.js')
short_hash = sha1(bundle).hexdigest()[:7]
bundle_filename = 'bundle-DISABLE_SEARCH-{}-SHARE-{}-MG_FILTER_TAGS-{}-SHORTSHA1-{}.js'.format( bundle_filename = 'bundle-DISABLE_SEARCH-{}-SHARE-{}-MG_FILTER_TAGS-{}-SHORTSHA1-{}.js'.format(
DISABLE_SEARCH, SHARE, MG_FILTER_TAGS, short_hash) DISABLE_SEARCH, SHARE, MG_FILTER_TAGS, short_hash)
with open('static/' + bundle_filename, 'wb') as bundle_file: with open('static/' + bundle_filename, 'wb') as bundle_file:
bundle_file.write(bundle) bundle_file.write(bundle)
sed('templates/base.html', '-SHORTSHA1-[a-z0-9]+.js', '-SHORTSHA1-{}.js'.format(short_hash))

View File

@ -52,7 +52,7 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
<link rel="stylesheet" type="text/css" href="{{SITEURL}}/theme/bundle-DISABLE_SEARCH-{{DISABLE_SEARCH|string|first|length|string|first}}-SHORTSHA1-cf29250.css"> <link rel="stylesheet" type="text/css" href="{{SITEURL}}/theme/bundle-DISABLE_SEARCH-{{DISABLE_SEARCH|string|first|length|string|first}}-SHORTSHA1-9f3bed7.css">
</head> </head>
<body> <body>
<!--[if lt IE 7]> <!--[if lt IE 7]>
@ -259,7 +259,7 @@
</div> </div>
</aside> </aside>
<script src="{{SITEURL}}/theme/bundle-DISABLE_SEARCH-{{DISABLE_SEARCH|string|first|length|string|first}}-SHARE-{{SHARE|string|first|length|string|first}}-MG_FILTER_TAGS-{{MG_FILTER_TAGS|string|first|length|string|first}}-SHORTSHA1-e15c693.js"></script> <script src="{{SITEURL}}/theme/bundle-DISABLE_SEARCH-{{DISABLE_SEARCH|string|first|length|string|first}}-SHARE-{{SHARE|string|first|length|string|first}}-MG_FILTER_TAGS-{{MG_FILTER_TAGS|string|first|length|string|first}}-SHORTSHA1-9eba27f.js"></script>
{% include 'disqus_count.html' %} {% include 'disqus_count.html' %}
{% include 'analytics.html' %} {% include 'analytics.html' %}