Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templates: add meta robot tags #390

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions invenio_theme/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noimageindex">
"""

THEME_GOOGLE_SITE_VERIFICATION = []
"""List of Google Site Verification tokens to be used.

Expand Down
10 changes: 10 additions & 0 deletions invenio_theme/templates/invenio_theme/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

{%- if description %}<meta name="description" content="{{ description }}" />{% endif %}
{%- if keywords %}<meta name="keywords" content="{{ keywords }}" />{% endif %}

{%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %}
{%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %}
<meta name="google-site-verification" content="{{google_id}}"/>
{%- endfor %}
{%- endif %}

{% set meta_generator = get_meta_generator() %}
{% if meta_generator %}
<meta name="generator" content="{{ 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 %}
<meta {{ meta_tag | xmlattr }}>
{% endfor %}

{%- endblock head_meta %}
{%- block head_title %}
{%- set title = title or _(config.THEME_SITENAME) or _('Invenio') %}
Expand Down
10 changes: 10 additions & 0 deletions invenio_theme/templates/semantic-ui/invenio_theme/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

{%- if description %}<meta name="description" content="{{ description }}" />{% endif %}
{%- if keywords %}<meta name="keywords" content="{{ keywords }}" />{% endif %}

{%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %}
{%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %}
<meta name="google-site-verification" content="{{google_id}}"/>
{%- endfor %}
{%- endif %}

{% set meta_generator = get_meta_generator() %}
{% if meta_generator %}
<meta name="generator" content="{{ 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 %}
<meta {{ meta_tag | xmlattr }}>
{% endfor %}

{%- endblock head_meta %}

{%- block head_title %}
Expand Down
Loading