diff --git a/frappe/templates/base.html b/frappe/templates/base.html index 0b82b3dac2..8c843a44a4 100644 --- a/frappe/templates/base.html +++ b/frappe/templates/base.html @@ -42,7 +42,11 @@ {{ head_include or "" }} {% endblock -%} - {%- block style %}{%- endblock -%} + {%- block style %} + {% if colocated_css -%} + + {%- endif %} + {%- endblock -%} {%- endfor -%} - {%- block script %}{%- endblock %} + {%- block script %} + {% if colocated_js -%} + + {%- endif %} + {%- endblock %} {%- block body_include %}{{ body_include or "" }}{% endblock -%} diff --git a/frappe/website/router.py b/frappe/website/router.py index db7e6f322c..263d5b0f07 100644 --- a/frappe/website/router.py +++ b/frappe/website/router.py @@ -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 %}\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\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