Site homepage seo question

I am trying to migrate my existing blog to Zola, which works great.
I want to display the index meta tag on the homepage only but not on /page/2/, instead of that I want to show the no index meta tag on all /page/... pages.

Specify different templates in the _index.html file of root and /page directories.

+++
title = "Title"
sort_by = "none"
template = "section.html"
page_template = "root-page.html" <- Change to something else for `page`
+++

Make slightly different template files or better is to create macros in a file such as header.html. One macro has the meta tag and the other doesnt.

{% macro header_root() %}
<head>
<meta name="robots" content="index">
...
</head>
{% endmacro header_root %}

{% macro header_page() %}
<head>
<meta name="robots" content="noindex">
...
</head>
{% endmacro header_page %}

Then import one – or the other – in the root.html or page.html which is

{% import "header.html" as header %}    

{{ header::header_root() }}

or

{% import "header.html" as header %}    

{{ header::header_page() }}

1 Like

I suppose another way is a condition based on the current url to avoid making several templates

{% if page.permalink =  'whateveritshouldbe` %}

    <meta name="robots" content="index">
{% else %}
    <meta name="robots" content="noindex">
{% endif %}

print out the page.permalink first to see what it is and isnt.

Or use [extra]

[extra]
is_home = true

{% if page.extra.is_home && page.extra.is_home == true %}
1 Like

I am trying to use {% if page.permalink == "{{ config.base_url }}" %} its shows Error: Reason: Variable page.permalink not found in context while rendering 'index.html'

Full Code is,

{% if page.permalink == "{{ config.base_url }}" %}
    <meta name="robots" content="max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
{% else %}
    <meta name="robots" content="noindex, noarchive, follow,max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
{% endif %}

I am trying to deindex pages generated by paginator.pages

the template you are rendering is used for both sections (or directories) and pages (files in those directories). sections don’t have page.permalink they use section.permalink

so you’re condition is going to test for section.permalink is null or defined.

{% if section.permalink %}
    <meta name="robots" content="max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
{% else %}
    <meta name="robots" content="noindex, noarchive, follow,max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
{% endif %}

that should work for all sections so you can perhaps add the base url also for any other sections. aka directories.

{% if section.permalink and section.permalink == config.base_url %}
    <meta name="robots" content="max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
{% else %}
    <meta name="robots" content="noindex, noarchive, follow,max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
{% endif %}

and perhaps add quotes if needed for base_url. not tested

1 Like

Nothings Works,
I achieved that condition with Apollo theme macro, but I have to call it using a different template for the website front page.

My Version:

    {% set current_path = current_path | default(value="/") %}
    {% if current_path == "/" %}
    <meta name="robots" content="max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
    {% else %}
    <meta name="robots" content="noindex, noarchive, follow,max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
    {% endif %}