Put single-page content into a separate js file (#10160)

This commit is contained in:
Ivan Blinkov 2020-04-09 23:50:39 +03:00 committed by GitHub
parent 2b51b5ee5f
commit 9326016e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -220,6 +220,19 @@ def build_single_page_version(lang, args, nav, cfg):
single_page_output_path
)
single_page_index_html = os.path.join(single_page_output_path, 'index.html')
single_page_content_js = os.path.join(single_page_output_path, 'content.js')
with open(single_page_index_html, 'r') as f:
sp_prefix, sp_js, sp_suffix = f.read().split('<!-- BREAK -->')
with open(single_page_index_html, 'w') as f:
f.write(sp_prefix)
f.write(sp_suffix)
with open(single_page_content_js, 'w') as f:
if args.minify:
import jsmin
sp_js = jsmin.jsmin(sp_js)
f.write(sp_js)
logging.info(f'Re-building single page for {lang} pdf/test')
with util.temp_dir() as test_dir:
extra['single_page'] = False

View File

@ -17,11 +17,7 @@
{% endif %}
{% if single_page and page.content %}
<script async type="text/javascript">
{% for chunk in page.content|chunks %}
document.write({{ chunk|tojson|safe }});
{% endfor %}
</script>
<script type="text/javascript" src="content.js?{{ config.extra.rev_short }}"></script>
{% endif %}
</div>
@ -32,3 +28,12 @@
</div>
{% endif %}
</div>
{% if single_page and page.content %}
<!-- BREAK -->
(function() {
{% for chunk in page.content|chunks %}
document.write({{ chunk|tojson|safe }});
{% endfor %}
})();
<!-- BREAK -->
{% endif %}