welpo/tabi

Sub-pages cause error

JVimes opened this issue · 10 comments

Bug Report

If I have a page in a folder under another page's folder, I get "Error: Failed to build the site".

Environment

Zola version: zola 0.19.2
tabi version or commit: 35dcf55

Expected Behavior

I think it should work.

Adding and last_ancestor to the following elif seems to workaround (fix?) the issue, at least at first glance:

{%- if section -%}
{%- set current_section = section -%}
{%- elif page -%}
{#- Retrieve last ancestor to determine current section, if applicable -#}
{%- set last_ancestor = page.ancestors | slice(start=-1) %}
{%- set current_section = get_section(path=last_ancestor.0, metadata_only=true) %}
{%- endif -%}

Current Behavior

Error: Failed to build the site
Error: Failed to render page '\\?\C:\path\Website2\content\foo\bar\baz\index.md'
Error: Reason: Failed to render 'page.html': error while rendering macro `macros_settings::evaluate_setting_priority` (error happened in 'base.html').
Error: Reason: Function call 'get_section' failed
Error: Reason: Variable `last_ancestor.0` not found in context while rendering 'macros/settings.html'

Step to Reproduce

Set up a page under another page and try to serve:

  • Page folder (index.md)
    • Subpage folder (index.md)

Thanks for reporting this.

Can you explain what the use case is? What's the goal of having a page inside a page? (And not a page inside a section, or a section inside a section)?

I have a page for a game we're writing, and sub-pages for its privacy policy, data deletion notice, etc.

Makes sense.

Could you share the tree structure? To replicate the issue.

Sure, the directory tree is:

  • content
    • page (with index.md)
      • subpage (with index.md)

Thanks!

I reproduced the issue no problem. It was simple enough to bypass the error (check for ancestors length), but that meant the hierarchy would break in nested pages.

I improved the feature so that the hierarchy looks for the nearest page/section when it has no parents. That means you can set your [extra] settings once on the parent page, and the children pages will follow them (unless overriden).

Fixed in #385.

That's great, thank you! 🎉

Thank you for your report and for using tabi!

@welpo I think there might be a bug. When I add social_media_card = "image.webp" to the parent page, header.html expects the child page to also have the file:

Could not get metadata for the specified social media card image in page /parent/child/. Attempted relative path: 'image.webp' and absolute path: 'image.webp'. Ensure the file exists at one of these locations.

That's a bug indeed.

Since the social media card setting follows the hierarchy (docs), it tries to find the relative path from the wrong place (the child page, when it's set on the parent).

I'm guessing this can also happen for sections.

Workarounds:

  • Use an absolute path
  • Set social_media_card = "" on the child page(s)

I'll look into a proper fix (i.e. look for the image relative to the nearest parent, where we found the non-empty social_media_card) soon.

That makes sense, thank you. Great workarounds for me. 👍