Versioned navigation?

Hey there!

We’ve decided to build our documentation site on Zola and it’s really cool so far, but I bumped into a problem: our structure for content is basically version/section/subsection/page and I’m struggling how to make global navigation for the current version. For the version picker, I simply used subsections of get_section('_index.md'), but I’m unsure how to provide versioned _index.md to my navigation.

What I need is basically:

  • get_section('1.0.0/_index.md') for version 1.0 of the documentation
  • get_section('1.1.0/_index.md') for 1.1.0
  • and so on

Is there any variable I can pass to get_section to make it work or do I have to hack section and/or page.ancestors?

Thanks for the kind words!

Is the repo open-source by any chance or can you provide a stripped down site so I can play with it?

Nope, it’s internal project, but I can probably strip it down a bit to the basics :slight_smile:

I made a hacky first version work using all sorts of sorcery:

      {% set current_section = current_path | as_str | split(pat="/") | first %}
      {% if current_section %}
        {% set section_array = [current_section | as_str, "_index.md"] %}
        {% set section_path = section_array | join(sep='/') %}
      {% else %}
        {% set section_path = '_index.md' %}
      {% endif %}
      {% set section = get_section(path=section_path) %}

Being a designer / front-end person myself, I am having a “my code doesn’t work and I don’t know why” to “my code works and I don’t know why” moment, but it’s good enough for v1.0 :smiley:

Tera does have string concatenation built-in so you can replace some of your code, eg

        {% set section_array = [current_section | as_str, "_index.md"] %}
        {% set section_path = section_array | join(sep='/') %}

can be

        {% set section_path = current_section ~ '/_index.md'%}

I don’t think as_str is needed in the first line as it should be a string already?

1 Like