diff --git a/oarepo_ui/ext.py b/oarepo_ui/ext.py index 90920cbe..2bc03740 100644 --- a/oarepo_ui/ext.py +++ b/oarepo_ui/ext.py @@ -3,9 +3,14 @@ from pathlib import Path from flask import Response, current_app +from flask_webpackext import current_manifest +from flask_webpackext.errors import ManifestKeyNotFoundError from importlib_metadata import entry_points from invenio_base.utils import obj_or_import_string from flask_login import user_logged_in, user_logged_out +from markupsafe import Markup + +from .proxies import current_optional_manifest from .utils import clear_view_deposit_page_permission_from_session @@ -20,6 +25,12 @@ def __init__(self, app): self.init_builder_plugin() self._catalog = None + def optional_manifest(self, key): + try: + return current_manifest[key] + except ManifestKeyNotFoundError as e: + return Markup(f"") + def reinitialize_catalog(self): self._catalog = None try: @@ -95,6 +106,7 @@ def init_app(self, app): app.extensions["oarepo_ui"] = OARepoUIState(app) user_logged_in.connect(clear_view_deposit_page_permission_from_session) user_logged_out.connect(clear_view_deposit_page_permission_from_session) + app.add_template_global(current_optional_manifest, name="webpack_optional") def init_config(self, app): """Initialize configuration.""" diff --git a/oarepo_ui/proxies.py b/oarepo_ui/proxies.py index c0a34008..a9bc8d1a 100644 --- a/oarepo_ui/proxies.py +++ b/oarepo_ui/proxies.py @@ -3,3 +3,6 @@ current_oarepo_ui = LocalProxy(lambda: current_app.extensions["oarepo_ui"]) """Proxy to the oarepo_ui state.""" + +current_optional_manifest = LocalProxy(lambda: current_oarepo_ui.optional_manifest) +"""Proxy to current optional webpack manifest.""" diff --git a/oarepo_ui/templates/oarepo_ui/javascript.html b/oarepo_ui/templates/oarepo_ui/javascript.html index b47fe1a4..464e2654 100644 --- a/oarepo_ui/templates/oarepo_ui/javascript.html +++ b/oarepo_ui/templates/oarepo_ui/javascript.html @@ -1,7 +1,6 @@ {% include "invenio_theme/javascript.html" %} - +{{ webpack['oarepo-overridable-registry.js'] }} {{ webpack['oarepo_ui_theme.js'] }} {{ webpack['oarepo_ui_components.js'] }} -{{ webpack['oarepo-overridable-registry.js'] }} - +{{ webpack_optional('overrides-' ~ request.endpoint ~ '.js') }}