From 557090fcb55e8d084335c3954d62d1385456a5ec Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Wed, 31 Jul 2024 15:01:39 +0200 Subject: [PATCH] templates: add meta robot tags * Generate robots meta tags from the `THEME_META_ROBOT_TAGS` config or exlicitly set via the `meta_robot_tags` Jinja variable. --- invenio_theme/config.py | 20 +++++++++++++++++++ .../templates/invenio_theme/page.html | 10 ++++++++++ .../semantic-ui/invenio_theme/page.html | 10 ++++++++++ 3 files changed, 40 insertions(+) diff --git a/invenio_theme/config.py b/invenio_theme/config.py index 66d7890..b31a0f4 100644 --- a/invenio_theme/config.py +++ b/invenio_theme/config.py @@ -91,6 +91,26 @@ Accepts a string or a func returning a string. Set it to `None` to disable it. """ +THEME_META_ROBOT_TAGS = [] +"""Robots meta tag to control indexing of the page. + +Accepts a list of dicts that will be converted into meta tag attributes, e.g.: + +.. code-block:: python + + THEME_META_ROBOT_TAGS = [ + {"name": "robots", "content": "noindex, nofollow"}, + {"name": "googlebot", "content": "noimageindex"}, + ] + +will generate: + +.. code-block:: html + + + +""" + THEME_GOOGLE_SITE_VERIFICATION = [] """List of Google Site Verification tokens to be used. diff --git a/invenio_theme/templates/invenio_theme/page.html b/invenio_theme/templates/invenio_theme/page.html index 8db0867..55b432a 100644 --- a/invenio_theme/templates/invenio_theme/page.html +++ b/invenio_theme/templates/invenio_theme/page.html @@ -14,17 +14,27 @@ + {%- 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 %} + + {# Add meta tags from an existing "meta_robot_tags" Jinja variable or config #} + {% set meta_robot_tags = meta_robot_tags or config.get("THEME_META_ROBOT_TAGS") %} + {% for meta_tag in meta_robot_tags %} + + {% endfor %} + {%- 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 5d43ae3..0006116 100644 --- a/invenio_theme/templates/semantic-ui/invenio_theme/page.html +++ b/invenio_theme/templates/semantic-ui/invenio_theme/page.html @@ -16,17 +16,27 @@ + {%- 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 %} + + {# Add meta tags from an existing "meta_robot_tags" Jinja variable or config #} + {% set meta_robot_tags = meta_robot_tags or config.get("THEME_META_ROBOT_TAGS") %} + {% for meta_tag in meta_robot_tags %} + + {% endfor %} + {%- endblock head_meta %} {%- block head_title %}