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

🐛 fix(header): check if translations exist while building tags #159

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

welpo
Copy link
Owner

@welpo welpo commented Sep 16, 2023

Description

This PR aims to resolves #158, the build-stopping bug when pages are missing translations for all config languages.

Changes Made

  1. Modified the Tera template to conditionally check for the existence of translated pages or sections before invoking get_page or get_section.
  2. Utilised load_data with required=false as a workaround to check for the existence of a .md file, thus preventing build errors.
{# Check if the translated page or section exists #}
{%- set translation_exists = load_data(path=translated_filename, required=false) -%}

{# Get the page or section details #}
{%- if translation_exists -%}
    {%- if page.relative_path -%}
        {%- set translated_page = get_page(path=translated_filename, metadata_only=true) -%}
    {%- else -%}
        {%- set translated_page = get_section(path=translated_filename, metadata_only=true) -%}
    {%- endif -%}
{%- endif -%}

Points to Consider

  • The use of load_data here is primarily a workaround due to the lack of a direct function to check for file existence in Zola (see this discussion). Therefore, this solution might not be the most idiomatic or efficient, but it serves the purpose of resolving the build-stopping issue.

@welpo welpo added the bug Something isn't working label Sep 16, 2023
@welpo welpo merged commit 271f54c into main Sep 16, 2023
1 check passed
@welpo welpo deleted the fix/multilingual-tags-missing-translations branch September 16, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mutlilingual tags force a post per language
1 participant