diff --git a/invenio_theme/config.py b/invenio_theme/config.py index e32e40b5..66d78902 100644 --- a/invenio_theme/config.py +++ b/invenio_theme/config.py @@ -85,10 +85,16 @@ THEME_ERROR_TEMPLATE = "invenio_theme/page_error.html" """Base template for error pages.""" +THEME_GENERATOR = "Invenio" +"""Generator meta tag to identify the software that generated the page. + +Accepts a string or a func returning a string. Set it to `None` to disable it. +""" + THEME_GOOGLE_SITE_VERIFICATION = [] """List of Google Site Verification tokens to be used. -This adds the Google Site Verfication into the meta tags of all pages. +This adds the Google Site Verification into the meta tags of all pages. """ THEME_LOGO = "images/invenio-white.svg" @@ -101,7 +107,7 @@ """Enable or disable basic frontpage view.""" THEME_FRONTPAGE_TITLE = _("Invenio") -"""The title shown on the fronpage.""" +"""The title shown on the frontpage.""" THEME_FRONTPAGE_TEMPLATE = "invenio_theme/frontpage.html" """Template for front page.""" diff --git a/invenio_theme/ext.py b/invenio_theme/ext.py index e37c7875..7ee6896a 100644 --- a/invenio_theme/ext.py +++ b/invenio_theme/ext.py @@ -10,6 +10,7 @@ """Invenio standard theme.""" from flask_menu import Menu +from invenio_base.utils import load_or_import_from_config from . import config from .icons import ThemeIcons @@ -64,6 +65,13 @@ def init_config(self, app): app.config.setdefault("ADMIN_BASE_TEMPLATE", config.ADMIN_BASE_TEMPLATE) + # inject the Meta-Generator string as a func in Jinja + def _generator_func_or_str(): + value = app.config.get("THEME_GENERATOR") + return value() if callable(value) else value + + app.jinja_env.globals["get_meta_generator"] = _generator_func_or_str + @property def icons(self): """Return icons.""" diff --git a/invenio_theme/templates/invenio_theme/page.html b/invenio_theme/templates/invenio_theme/page.html index feef6209..8db0867e 100644 --- a/invenio_theme/templates/invenio_theme/page.html +++ b/invenio_theme/templates/invenio_theme/page.html @@ -21,6 +21,10 @@ {%- endfor %} {%- endif %} + {% set meta_generator = get_meta_generator() %} + {% if meta_generator %} + + {%- endif %} {%- endblock head_meta %} {%- block head_title %} {%- set title = title or _(config.THEME_SITENAME) or _('Invenio') %} diff --git a/invenio_theme/templates/invenio_theme/page_admin.html b/invenio_theme/templates/invenio_theme/page_admin.html index e3d42408..0c6b441c 100644 --- a/invenio_theme/templates/invenio_theme/page_admin.html +++ b/invenio_theme/templates/invenio_theme/page_admin.html @@ -17,18 +17,24 @@
{%- block head %} {%- block head_meta %} - - - - {%- if description %} - {% endif %} - {%- if keywords %} - {% endif %} - {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %} - {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %} - - {%- endfor %} - {%- endif %} + + + + {%- if description %} + + {% endif %} + {%- if keywords %} + + {% endif %} + {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %} + {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %} + + {%- endfor %} + {%- endif %} + {% set meta_generator = get_meta_generator() %} + {% if meta_generator %} + + {%- endif %} {%- endblock head_meta %} {%- block head_title %} {%- set title = title or _(config.THEME_SITENAME) or _('Invenio') %} diff --git a/invenio_theme/templates/semantic-ui/invenio_theme/page.html b/invenio_theme/templates/semantic-ui/invenio_theme/page.html index 5f5f3707..5d43ae33 100644 --- a/invenio_theme/templates/semantic-ui/invenio_theme/page.html +++ b/invenio_theme/templates/semantic-ui/invenio_theme/page.html @@ -13,16 +13,20 @@ {%- block head %} {%- block head_meta %} - - - - {%- if description %}{% endif %} - {%- if keywords %}{% endif %} - {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %} - {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %} - - {%- endfor %} - {%- endif %} + + + + {%- if description %}{% endif %} + {%- if keywords %}{% endif %} + {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %} + {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %} + + {%- endfor %} + {%- endif %} + {% set meta_generator = get_meta_generator() %} + {% if meta_generator %} + + {%- endif %} {%- endblock head_meta %} {%- block head_title %} diff --git a/invenio_theme/templates/semantic-ui/invenio_theme/page_admin.html b/invenio_theme/templates/semantic-ui/invenio_theme/page_admin.html index e3d42408..93f713b4 100644 --- a/invenio_theme/templates/semantic-ui/invenio_theme/page_admin.html +++ b/invenio_theme/templates/semantic-ui/invenio_theme/page_admin.html @@ -17,18 +17,24 @@ {%- block head %} {%- block head_meta %} - - - - {%- if description %} - {% endif %} - {%- if keywords %} - {% endif %} - {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %} - {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %} - - {%- endfor %} - {%- endif %} + + + + {%- if description %} + + {% endif %} + {%- if keywords %} + + {% endif %} + {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %} + {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %} + + {%- endfor %} + {%- endif %} + {% set meta_generator = get_meta_generator() %} + {% if meta_generator %} + + {%- endif %} {%- endblock head_meta %} {%- block head_title %} {%- set title = title or _(config.THEME_SITENAME) or _('Invenio') %} diff --git a/tests/test_invenio_theme.py b/tests/test_invenio_theme.py index 8c0da25c..91eab396 100644 --- a/tests/test_invenio_theme.py +++ b/tests/test_invenio_theme.py @@ -207,3 +207,29 @@ def test_frontpage_exists(app_frontpage_handler): with app_frontpage_handler.test_client() as client: response = client.get("/") assert b"Jessica Jones" in response.data + + +def test_meta_generator(app): + """Test meta generator tag.""" + # remove css/js to avoid generating assets + base_tpl = r"""{% extends 'invenio_theme/page.html' %} + {% block css %}{% endblock %} + {% block javascript %}{% endblock %} + """ + + InvenioTheme(app) + InvenioAssets(app) + + with app.test_request_context(): + app.config.update(dict(THEME_GENERATOR=None)) + assert '