Merge pull request #11067 from surajshetty3416/fix-website
fix(website): Properly load colocated javascript and style
This commit is contained in:
commit
ff54ff13f3
2 changed files with 21 additions and 17 deletions
|
|
@ -42,7 +42,11 @@
|
|||
{{ head_include or "" }}
|
||||
{% endblock -%}
|
||||
|
||||
{%- block style %}{%- endblock -%}
|
||||
{%- block style %}
|
||||
{% if colocated_css -%}
|
||||
<style>{{ colocated_css }}</style>
|
||||
{%- endif %}
|
||||
{%- endblock -%}
|
||||
|
||||
<script>
|
||||
window.frappe = {};
|
||||
|
|
@ -86,7 +90,11 @@
|
|||
<script type="text/javascript" src="{{ link | abs_url }}"></script>
|
||||
{%- endfor -%}
|
||||
|
||||
{%- block script %}{%- endblock %}
|
||||
{%- block script %}
|
||||
{% if colocated_js -%}
|
||||
<script>{{ colocated_js }}</script>
|
||||
{%- endif %}
|
||||
{%- endblock %}
|
||||
<!-- csrf_token -->
|
||||
{%- block body_include %}{{ body_include or "" }}{% endblock -%}
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -283,22 +283,18 @@ def setup_source(page_info):
|
|||
# set the source only if it contains raw content
|
||||
html = source
|
||||
|
||||
# load css/js files
|
||||
js, css = '', ''
|
||||
# load css/js files
|
||||
js_path = os.path.join(page_info.basepath, (page_info.basename or 'index') + '.js')
|
||||
if os.path.exists(js_path) and '{% block script %}' not in html:
|
||||
with io.open(js_path, 'r', encoding = 'utf-8') as f:
|
||||
js = f.read()
|
||||
page_info.colocated_js = js
|
||||
|
||||
js_path = os.path.join(page_info.basepath, (page_info.basename or 'index') + '.js')
|
||||
if os.path.exists(js_path):
|
||||
if not '{% block script %}' in html:
|
||||
with io.open(js_path, 'r', encoding = 'utf-8') as f:
|
||||
js = f.read()
|
||||
html += '\n{% block script %}<script>' + js + '\n</script>\n{% endblock %}'
|
||||
|
||||
css_path = os.path.join(page_info.basepath, (page_info.basename or 'index') + '.css')
|
||||
if os.path.exists(css_path):
|
||||
if not '{% block style %}' in html:
|
||||
with io.open(css_path, 'r', encoding='utf-8') as f:
|
||||
css = f.read()
|
||||
html += '\n{% block style %}\n<style>\n' + css + '\n</style>\n{% endblock %}'
|
||||
css_path = os.path.join(page_info.basepath, (page_info.basename or 'index') + '.css')
|
||||
if os.path.exists(css_path) and '{% block style %}' not in html:
|
||||
with io.open(css_path, 'r', encoding='utf-8') as f:
|
||||
css = f.read()
|
||||
page_info.colocated_css = css
|
||||
|
||||
if html:
|
||||
page_info.source = html
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue